I use Haml for my templates, and I mostly love using it and find it very intuitive. However, there are a few things that seem to trip me up on a regular basis, and I constantly find myself googling for the same Stack Overflow posts … so now I’m doing something I should have done ages ago and just posting them here for easy reference. Hopefully they might even help somebody else.
Don’t escape my HTML
By default, Haml escapes HTML, because in most cases this helps protect from XSS – but sometimes it’s my HTML and I know it’s safe, so I don’t want it escaped – or maybe I really just wanna let the bad guys hack me. For this, use an exclamation mark (!).
!= "I like my html UNESCAPED!!"
Thank you Haml Docs.
Ever want to do a link followed by a comma? You know, like that? Only if you do that in Haml:
You %a know , like that?
It comes out with a space: You know , like that? But you can fix it with the greater than operator, >, which removes all whitespace surrounding the tag.
You %a> know , like that?
The Haml docs contain a lot of other useful stuff, but these are at least two things that I am tired of looking up!