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 {{ }}?
I use:
_.templateSettings = {
evaluate : /\{\[([\s\S]+?)\]\}/g,
interpolate : /\{\{([\s\S]+?)\}\}/g
};
Then instead of <%= … %> use {{ … }} and instead of <% … %> use {[ … ]}
http://handlebarsjs.com/ is mustache with logic, partials, helpers & context. It can also be precompiled. A must IMHO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With