Random Haml tips

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

  1. Posted February 5, 2009 at 2:08 am | Permalink

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

  2. Posted February 5, 2009 at 12:35 pm | Permalink

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

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">