# Render text with Tangular templates

> Use Tangular.render() to fill templates for e-mails, documents and messages with conditions, loops and helpers.

Framework: total5
Product: Total.js 5 (total5@0.0.19)
Language: en
Content-SHA256: a9ede48ee69cee4e1176df474051b6296e98174aab3a8d9a816017d0bf6e43e1
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

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.

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