---
title: Tangular
project: Total.js V5
version: 0.0.20
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/reference/tangular/
updated: 2026-11-18T16:56:54.572Z
---

# Tangular

> Tangular.compile(), Tangular.render(), Tangular.register() and Tangular.helpers.

## API

### Tangular.compile(template, [tagbeg], [tagend])

Type: `method`

Compiles a Tangular template into a function.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | The template. |
| `tagbeg` | `String` | no | `'{{'` | Start of a command. |
| `tagend` | `String` | no | `'}}'` | End of a command. |

Returns: `Function` `function(model, [repository], [helpers])`.

The function is `template(model, [repository], [helpers])` and returns a string. Names in the template are read from the model, `$` is the repository and `$index` the index in a loop. Errors while rendering are printed to the console. `tagbeg` and `tagend` replace `{{` and `}}` (as parts of a regular expression). Commands are described in [Views](../../guides/views/#templates).

Example: Compile once
```js
var row = Tangular.compile('<tr><td>{{ name }}</td><td>{{ price | format(2) }}</td></tr>');
var html = items.map(item => row(item)).join('');
```

Example: Local helpers
```js
var t = Tangular.compile('{{ name | badge }}');
t({ name: 'New' }, null, { badge: function(value) { return '<span class="badge">' + value + '</span>'; } });
```

### Tangular.render(template, [model], [repository], [helpers])

Type: `method`

Compiles and renders a template in one call.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | The template. |
| `model` | `Object` | no | `{}` | The model. |
| `repository` | `Object` | no |  | Available as `$`. |
| `helpers` | `Object` | no |  | Helpers for this call. |

Returns: `String` The output.

Use `Tangular.compile()` for templates that you render often.

Example: Render
```js
Tangular.render('Hello {{ name }}!', { name: 'Peter' }); // 'Hello Peter!'
```

### Tangular.register(name, fn)

Type: `method`

Adds a helper for all Tangular templates.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Helper name. |
| `fn` | `Function` | yes |  | `function(value, [args...])`. |

Returns: `Object` Tangular, for chaining.

The helper is called as `fn.call(model, value, ...arguments)`: `{{ price | money('EUR') }}` calls `money(price, 'EUR')`. A missing helper prints a warning and returns the value.

Example: Helper
```js
Tangular.register('money', function(value, currency) {
	return value.format(2) + ' ' + (currency || 'EUR');
});
```

### Tangular.helpers

Type: `property`

Built-in helpers of Tangular, also available as the global `Thelpers`.

Returns: `Object`

| Helper | Description |
| --- | --- |
| `encode([type])` | HTML-encodes; used for every value without `raw`. Types: `json`, `json2`, `url`, `querify` |
| `raw` | The value without encoding |
| `format([format], ...)` | Formats a number or a date (strings are detected) |
| `currency([code])` | Formats a number with a formatter from `DEF.currencies[code]` (or `DEF.currencies.default`); without one it uses two decimals |
| `pluralize(zero, one, few, other)` | Chooses a word by a number |
| `empty([text])`, `def([text])` | The value, or `text` (default `---`) when it is empty |

Example: Usage
```js
Tangular.render('{{ count | pluralize(\'no items\', \'# item\', \'# items\', \'# items\') }}', { count: 3 });
```
