HAML & # 8594; Trunk Template, Unescaping HTML Parameters

I use HAML to create templates for the Backbone.js application. I need to be able to insert <%= blah %> as an html a la attribute:

 %a{:href => "myresources/<% id %>"} My Resource 

and bring it out

 <a href='myresources/<%= id %>' >My Resource</a> 

in the html template. Unfortunately, HAML avoids the html options, leaving me with

 <a href='#myresources/&lt;%= id %&gt;'>My Resource</a> 

According to the HAML Reference '!' The operator can be used for unescaping strings, but not inside HTML attributes.

Also, I would use plaintext to display the anchor tag, but since the anchor tag is the root of this particular view, I lose all the benefits of using HAML.

Any help?

Update I didn’t mention it, but I use LiveReload to actually monitor my file system and run the haml compiler, and the option to disable HTML screens in tag attributes was set in LiveReload. <head slap> If someone else encounters this problem outside of LiveReload, you can also set the parameter :escape_attrs to false when configuring your HAML installation.

+3
source share
2 answers

You can configure HAML to avoid tag attributes using the escape_attrs parameter in your HAML configuration. See HAML Settings .

+3
source

You can try using html_safe, which is a method for String objects. This will cause the html characters in the variable expression (e.g.) to be left unchanged to underline:

 %a{:href => "myresources/<% id %>".html_safe} My Resource 

Found in response to Interpolate html internal attributes using Underscore.js

0
source

All Articles