Meta Descritpion in HAML with an external variable

I am trying to get my meta description to work in HAML, and everything I'm trying to do is throwing errors.

%meta{:name => "description", :content => "Some content"}/
%title 
  = data.page.title

The code above is executed. Now I will try the following:

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

And I get an error with unbalanced brackets in the first line. What am I doing wrong?

+5
source share
1 answer

In HAML, the hash that you use to specify attributes for an element may contain valid Ruby code, so you don't need to use =Ruby expressions to evaluate. Therefore, the code you are looking for is simple:

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

, / %meta, HAML , img br.

+16

All Articles