haml 在元关键字的 rails 布局中使用变量
haml using variable in rails layout for meta keywords
我们想根据具体操作调整网页的元关键字。作为 haml 的新手,有没有一种方法可以通过 provides
语句来完成。例如:
在client.html.haml
- provide(:keywords, 'here are unique keywords')
在我们的 application.html.haml 中,我们将如何做到这一点?喜欢:
%meta{ name: "keywords", content: #{yield(:keywords)} ||= default keywords
但这不起作用。
你没有说 为什么 你的方法不起作用,所以我猜这是你的 haml 中的语法错误(缺少右括号)。此外,我不确定 default keywords
是什么或您为什么使用 ||=
运算符 - 这些中的任何一个也可能导致您的解决方案 "not work".
类似下面的内容将按预期工作:
# application.html.haml
%meta{ name: "keywords", |
content: content_for?(:keywords) ? yield(:keywords) : "default" }
# this could also be achieved using content_for?(:keywords) || "default"
# client.html.haml
- provide :keywords do
this should work
我们想根据具体操作调整网页的元关键字。作为 haml 的新手,有没有一种方法可以通过 provides
语句来完成。例如:
在client.html.haml
- provide(:keywords, 'here are unique keywords')
在我们的 application.html.haml 中,我们将如何做到这一点?喜欢:
%meta{ name: "keywords", content: #{yield(:keywords)} ||= default keywords
但这不起作用。
你没有说 为什么 你的方法不起作用,所以我猜这是你的 haml 中的语法错误(缺少右括号)。此外,我不确定 default keywords
是什么或您为什么使用 ||=
运算符 - 这些中的任何一个也可能导致您的解决方案 "not work".
类似下面的内容将按预期工作:
# application.html.haml
%meta{ name: "keywords", |
content: content_for?(:keywords) ? yield(:keywords) : "default" }
# this could also be achieved using content_for?(:keywords) || "default"
# client.html.haml
- provide :keywords do
this should work