_. Templating using Handlebars syntax

http://stackoverflow.com/questions/15624922/underscore-interpolate-settings

by kyllle

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script id="t" type="text/x-underscore">
    <div><%= title %> | {{ title }}</div>
    <div><%= title %> | {{= title }}</div>
    <div><%= title %> | {{- title }}</div>
</script>

JavaScript

_.templateSettings = {
    evaluate:    /\{\{(.+?)\}\}/g,
    interpolate: /\{\{=(.+?)\}\}/g,
    escape:      /\{\{-(.+?)\}\}/g
};
var t = _.template($('#t').html());
console.log(t({ title: '<p>pancakes</p>' }));