I’m trying to get my meta description to work in HAML and everything I try produces errors.
%meta{:name => "description", :content => "Some content"}/
%title
= data.page.title
The code above works. Now I try the following:
%meta{:name => "description", :content =>
= data.page.desc
}/
%title
= data.page.title
And I get unbalanced brackets error on the first line. What am I doing wrong?
In HAML, the hash that you use to specify the attributes for an element can contain valid Ruby code, so you don’t need to use
=to evaluate a Ruby expression. Therefore, the code you’re looking for is simply:Note that you don’t need to append a
/to the end of the%metaelement declaration, as HAML will automatically treat it as a self-closing tag, likeimgorbr.