Article / January 31, 2009

Random Haml tips

By Dejan Simic/1485 Views/2 Comments
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.

Comments

Posted by Zeke Sikelianos on about 1 year ago8f344b1c4bdcfc28bd848e97e94c3523?s=30

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..

Posted by Dejan Simic on about 1 year agoDe0ba549099a6d7e54e41edf73777d7d?s=30

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

Add a Comment