I have a Backbone.js application hosted in Sinatra and rendered via an ERB script. The backbone templates are using the underscore template functionality so the variables are rendered in ERB like so:
<div id="<%%= variable %>">
The extra “%” escapes the rendering of that variable and renders it with a single “%” which is what the underscore template library would pick up.
I tried the following while upgrading to HAML:
#"<%= id %>"
Which did not work. How do I accomplish the same task with HAML?
First, you can’t use the
#shortcut to create anidwith a value like that, you’ll have to do it the long way:By default, Haml will escape the attributes, so this will produce something like:
which is probably not what you want. You can turn of escaping of attributes by setting the
:escape_attrsoption to false. This will then produce the desired output:Note that this option effects all attributes in the document.
An alternative would be to use a different set of delimiters in your templates. For example you could use
{{...}}with this:Now Haml won’t escape the attribute values.