0

Is there a way to render some haml-generated DOM into an element's attribute? A concrete usage example would be a bootstrap tooltip which allows html in its "title"-attribute.

I have tried to define a local variable but this syntax does not work:

!!! 5
  %body
    - tooltipDom =
      %i Some
      %strong very complex
      %i DOM

    %a{:"data-html" => "true", :title => tooltipDom, :"data-toggle" => "tooltip"}

What would be working syntax to get this html into the variable? Or is there another way to achieve this, e.g. rendering a partial inside the attribute somehow?

Please do not just suggest to simply write pure HTML-markup into the attribute. That is clearly not what I am looking for.

Community
  • 1
  • 1

1 Answers1

0

Defining the desired Haml in a partial and rendering that into the variable will work fine and do the job:

!!! 5
  %body
    - tooltipDom = render partial: 'some_partial'

    %a{:"data-html" => "true", :title => tooltipDom, :"data-toggle" => "tooltip"}