Render text with Tangular templates
Tangular is the small template language of Total.js (it also runs in the browser with jComponent). Write {{ value }} to print an escaped value, {{ if expression }}...{{ fi }} for conditions and {{ foreach item in list }}...{{ end }} for loops. Tangular.render(template, model) returns the text; use Tangular.compile(template) once and call the result many times for hot paths.
Variables are read from the model, so {{ user.name }} reads model.user.name. Output is HTML-escaped; add the raw helper ({{ html | raw }}) only for trusted content.
exports.install = function() {
ROUTE('POST /preview/', preview);
};
var template = 'Hello {{ name }}!{{ if vip }} Thanks for being a VIP.{{ fi }}\n{{ foreach item in items }}- {{ item.title }}\n{{ end }}';
function preview($) {
$.plain(Tangular.render(template, $.body));
}