Reputation: 2712
I use underscore.js for HTML Templating, set to use mustache syntax, like this: {{ }}
I have this code:
<% if (typeof(date) != "undefined") { %>
<span class="date"><%= date %></span>
<% } %>
How can I translate it to an underscore.js mustache-style template, using {{ }}
?
Upvotes: 10
Views: 3549
Reputation: 1
just include this code after append underscore
_.templateSettings = {
interpolate:/\{\{(.+?)\}\}/g
};
Upvotes: -1
Reputation: 3700
http://handlebarsjs.com/ is mustache with logic, partials, helpers & context. It can also be precompiled. A must IMHO.
Upvotes: 1
Reputation: 13105
I use:
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
Then instead of <%= … %>
use {{ … }}
and instead of <% … %>
use {[ … ]}
Upvotes: 19