Splitting HAML code into multiple lines

by Melvin Ram

If you’re using HAML and have a really long piece of code, you probably want to split it into multiple lines so it looks clean. Here’s how you do it.

Let’s say you have this code:

%h1.logo= real_account? && current_account.name ? current_account.name : AppConfig['app_name']

But you’d rather have:

%h1.logo= real_account? && current_account.name ? 
          current_account.name : AppConfig['app_name']

All you need is to pipe them using |, like this:

%h1.logo= real_account? && current_account.name ? |
          current_account.name : AppConfig['app_name'] |

Notice how the last line also has a |. That is required.

{ 2 comments… read them below or add one }

justin January 26, 2009 at 6:28 pm

Awesome – too bad TextMate gets all stupid on the syntax highlighting when you do this. Ditto when you drop into the :javascript tag.

Mel April 22, 2009 at 6:09 pm

@justin – yea, I know. Maybe we can get haml bundle maintainer to add support for this. Anyone know who that person is?

Leave a Comment