I want to use underscorejs' templating function. It seems like HTML5's <template>
tag would be an AMAZING fit for this, but there's a snag... The underscorejs interpolation tags (<%
and %>
get html-escaped, so HTML inside a template tag looks like so:
$('template.new-email').html()
=>
"
<div class="email">
<div class="timestamp">
<%= received %>
</div>
<div class="from">
<%= from %>
</div>
<div class="title">
<%= title %>
</div>
<div class="message">
<%= message %>
</div>
</div>
"
Well, that sucks.
Now, as it turns out, if I use a script tag with a fictitious type, like "x-underscore-templates", then it looks hunky-dory:
$('.new-email').html()
=>
"
<div class="email">
<div class="timestamp">
<%= received %>
</div>
<div class="from">
<%= from %>
</div>
<div class="title">
<%= title %>
</div>
<div class="message">
<%= message %>
</div>
</div>
"
So my question is -- can I use the template tag? How do I get just the characters I need, in a string, so I can pass them to underscore's templating system?
Note - since the server I'm using right now is a hapijs / node server that uses handlebars as a server-side templating system, I can't just use {{ and }}.