Single Page App – HTML Templates With Logic Using Underscore, LoDash
Underscore complement to JavaScript’s standard library. And it also gives you simple templating.
The Underscore template function compiles JavaScript templates into functions that can be evaluated for rendering. Template functions can both interpolate variables or execute arbitrary JavaScript code. That allows you to put more logic than you can with Mustache.
Comparison to Mustache, Handlebars
Mustache and Handlebars are what are known as “logic-less template engines.” With those libraries you cannot include any overly complex logic in the template. You get the most basic control structures needed to output data, keeping the HTML (or other content) clean.
Underscore is different. It’s a JavaScript library in itself, like Prototype or jQuery, and comes with it’s own templating engine. The templates have access to any method or helpers within the library, meaning the templates are strictly tied to JavaScript and house a lot more of the logic.
Continue reading “Single Page App – HTML Templates With Logic Using Underscore, LoDash”