Blog

Jan
30
Random Haml tips
by ELC | Article

Afedc256f1d9f96d2c0fdb77b1ed472cee75157d_1233363406_0

1. Multiline code block with |


= link_to "Back", root_path, |
:class => "back", :accesskey => "b", |
:title => "Go back (ctrl-b)" |

Although for this example, you’ll be better off creating helper method for it.

2. Two types of comment

Make sure you use the one you need.


/ this will be translated to HTML comment, visible to anyone

-# and this will not, so use this one for dev. notes

3. One-liners

Not very pretty, but they do the job.


== #{label_tag "Email"}:


= label_tag('Email'), ':'

4. Use &= to sanitize any HTML-sensitive characters

Not that anything is wrong with h(), but I like this better.


%p
&= @comment.body

5. Visit Haml reference page

For more stuff about Haml you might not know about go here.

2 Comments
February 5, 2009

Hey Dejan, do you use Textmate? If so, what HAML/SASS bundle are you using? Mine doesn’t seem to support syntax highlighting for the multiline pipe trick..

February 5, 2009

Neither does mine (the one hosted at macromates.com).