Bruce Lin
Bruce Lin

Reputation: 2740

Set attributes in haml using variable in mustache

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?

Upvotes: 0

Views: 186

Answers (2)

Yevgeniy Anfilofyev
Yevgeniy Anfilofyev

Reputation: 4847

You could use :plain, something like this:

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

Upvotes: 0

silvabox
silvabox

Reputation: 61

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}

Upvotes: 1

Related Questions