I think you're misunderstanding how <%=...%>
and <%-...%>
work in Underscore templates. From the fine manual:
Template functions can both interpolate variables, using
<%= … %>
,
[...]
If you wish to interpolate a value, and have it be HTML-escaped, use<%- … %>
So if you say <%= v %>
, v
goes right into the template as-is, if you say <%- v %>
then v
will be HTML escaped before going into the template. Consider a simple template like this:
<script id="t" type="text/x-underscore">
<%=: <%= html %>
<br>
<%-: <%- html %>
</script>
and throw some HTML at it:
var t = _.template($('#t').html());
$(whatever).html(
t({ html: '<span>html</span>' })
);
Given that input, you'll get this output:
<%=: <span>html</span>
<%-: <span>html</span>
Demo: http://jsfiddle.net/ambiguous/pL92b/
Your tags
comes from the server with embedded HTML:
'tags' => '<a href="http://google.com">Tag 1</a>'
but you're escaping that HTML in your template:
<p><span>Tags:</span><%- tags %></p>
You should be able to switch to simple interpolation:
<p><span>Tags:</span><%= tags %></p>
<!-- ------------------^ -->
to sort out your display.