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