使用小胡子中的变量在 haml 中设置属性
Set attributes in haml using variable in mustache
我在前端使用 haml 和 mustache。有一段代码:
.module-subtitle
{{title}}
我想显示带有 title 属性的 .module-subtitle 的工具提示,使用 {{title}} 中的内容。我试过了
.module-subtitle{ :"title" => {{title}}}
{{title}}
但它没有工作,因为它有语法错误。有什么提示吗?
没有看到更多您的代码和 运行 一些实验,我最初猜测这是模板渲染的顺序。如果 Haml 先渲染,那么它不会喜欢 .module-subtitle{ :"title" => {{title}}}
。如果 Mustache 首先运行,它应该将 .module-subtitle{ :"title" => {{title}}}
替换为 .module-subtitle{ :"title" => YourTitle}
但还要注意,在这种情况下 YourTitle 不是字符串分隔的。
如果您的对象在 haml 渲染上下文中可用,那么您可以将它留给 haml 渲染吗? .module-subtitle{ title: my_object.title}
你可以使用 :plain
,像这样:
:plain
<div class="module-subtitle" title="{{title}}">
{{title}}
</div>
我在前端使用 haml 和 mustache。有一段代码:
.module-subtitle
{{title}}
我想显示带有 title 属性的 .module-subtitle 的工具提示,使用 {{title}} 中的内容。我试过了
.module-subtitle{ :"title" => {{title}}}
{{title}}
但它没有工作,因为它有语法错误。有什么提示吗?
没有看到更多您的代码和 运行 一些实验,我最初猜测这是模板渲染的顺序。如果 Haml 先渲染,那么它不会喜欢 .module-subtitle{ :"title" => {{title}}}
。如果 Mustache 首先运行,它应该将 .module-subtitle{ :"title" => {{title}}}
替换为 .module-subtitle{ :"title" => YourTitle}
但还要注意,在这种情况下 YourTitle 不是字符串分隔的。
如果您的对象在 haml 渲染上下文中可用,那么您可以将它留给 haml 渲染吗? .module-subtitle{ title: my_object.title}
你可以使用 :plain
,像这样:
:plain
<div class="module-subtitle" title="{{title}}">
{{title}}
</div>