ForgeTotal.js 5
en

Total.js 5

Render text with Tangular templates

Total.js 5 · total5@0.0.19 templatescontent Executed against Total.js 5

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.

controllers/mail.js
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));
}