tags:

views:

48

answers:

2

I want to be able to have two Haml elements on the same line. For example:

%h1 %a{:href => '/'} Professio.

That doesn't work. How would I get something like this to work without borking?

A: 

You can do so, beacause haml elements can not be online

%h1 <a href='/'>Lorem ipsum</a>

Why you wouldn't like this solution?

%h1 
  %a{:href => '/'} Professio.

You can write special 'helper' method(that generate html link) for this cases like link_to in Rails.

%h1= link_to 'Professio', root_url
edtsech
I would like it on the same line because I want the output HTML to be on the same line.I'll just do multiple lines, thanks.
Ethan Turkeltaub
A: 

If you're looking to preserve the HTML on the same line you could try something like this:

irb(main):045:0> print Haml::Engine.new("%h1<\n %a{:href => '/'} Profession.").render() <h1><b href='/'>Profession.</a></h1>

Found here: HAML whitespace removal

[Edit: I know that's says b href above...]

SundayEdition