ForgeTotal.js 5
it

Total.js 5

Generare testo con i template Tangular

Total.js 5 · total5@0.0.19 templatescontent Eseguita con Total.js 5

Tangular è il piccolo linguaggio di template di Total.js (gira anche nel browser con jComponent). Scrivi {{ value }} per stampare un valore con escape, {{ if expression }}...{{ fi }} per le condizioni e {{ foreach item in list }}...{{ end }} per i cicli. Tangular.render(template, model) restituisce il testo; usa Tangular.compile(template) una volta e chiama il risultato molte volte nei percorsi critici.

Le variabili vengono lette dal modello, quindi {{ user.name }} legge model.user.name. L'output viene sottoposto a escape HTML; aggiungi l'helper raw ({{ html | raw }}) solo per contenuti affidabili.

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));
}