[英]Meta Descritpion in HAML with outside variable
I'm trying to get my meta description to work in HAML and everything I try produces errors. 我试图让我的元描述在HAML中工作,我尝试的一切都会产生错误。
%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. 在HAML中,用于指定元素属性的哈希可以包含有效的Ruby代码,因此您不需要使用=
来评估Ruby表达式。 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
. 请注意,您不需要在%meta
元素声明的末尾附加/
,因为HAML会自动将其视为自动关闭标记,例如img
或br
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.