Set attributes in haml using variable in mustache

家住魔仙堡 提交于 2019-12-12 03:15:55

问题


I'm using both haml and mustache for frontend. There is a code snippet:

.module-subtitle
  {{title}}

I want to show a tooltip for .module-subtitle with title attribute, using the content inside {{title}}. I tried

.module-subtitle{ :"title" => {{title}}}
  {{title}}

but it didn't work as it has syntax error. Any hints?


回答1:


You could use :plain, something like this:

:plain
  <div class="module-subtitle" title="{{title}}">
    {{title}}
  </div>



回答2:


Without seeing more of your code and running some experiments, I would guess initially that it's the order of the template rendering. If Haml is rendering first, then it will not like .module-subtitle{ :"title" => {{title}}}. If Moustache runs first, it should replace .module-subtitle{ :"title" => {{title}}} with .module-subtitle{ :"title" => YourTitle} but note also that in this case YourTitle is not string delimited.

If your object is available in the haml rendering context, then you could leave it to haml to render? .module-subtitle{ title: my_object.title}



来源:https://stackoverflow.com/questions/28410996/set-attributes-in-haml-using-variable-in-mustache

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!