Meta Descritpion in HAML with outside variable
Asked Answered
S

1

6

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?

Samaveda answered 4/2, 2012 at 19:23 Comment(1)
Just for information here unbalanced brackets error is created because HAML only allow line breaks directly after a commaOppose
I
21

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:

%meta{:name => "description", :content => data.page.desc}

Note that you don't need to append a / to the end of the %meta element declaration, as HAML will automatically treat it as a self-closing tag, like img or br.

Interface answered 4/2, 2012 at 20:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.