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

# Tangular

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

## API

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

Type: `method`

Compila un template Tangular in una funzione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Il template. |
| `tagbeg` | `String` | no | `'{{'` | Inizio di un comando. |
| `tagend` | `String` | no | `'}}'` | Fine di un comando. |

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

La funzione è `template(model, [repository], [helpers])` e restituisce una stringa. I nomi nel template vengono letti dal modello, `$` è il repository e `$index` l'indice in un ciclo. Gli errori durante il rendering vengono stampati nella console. `tagbeg` e `tagend` sostituiscono `{{` e `}}` (come parti di un'espressione regolare). I comandi sono descritti in [View](../../guides/views/#templates).

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

Example: Helper locali
```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`

Compila ed esegue il rendering di un template in una sola chiamata.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Il template. |
| `model` | `Object` | no | `{}` | Il modello. |
| `repository` | `Object` | no |  | Disponibile come `$`. |
| `helpers` | `Object` | no |  | Helper per questa chiamata. |

Returns: `String` L'output.

Usa `Tangular.compile()` per i template di cui esegui spesso il rendering.

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

### Tangular.register(name, fn)

Type: `method`

Aggiunge un helper per tutti i template Tangular.

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

Returns: `Object` Tangular, per il concatenamento.

L'helper viene chiamato come `fn.call(model, value, ...arguments)`: `{{ price | money('EUR') }}` chiama `money(price, 'EUR')`. Un helper mancante stampa un avviso e restituisce il valore.

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

### Tangular.helpers

Type: `property`

Gli helper integrati di Tangular, disponibili anche come variabile globale `Thelpers`.

Returns: `Object`

| Helper | Descrizione |
| --- | --- |
| `encode([type])` | Codifica in HTML; usato per ogni valore senza `raw`. Tipi: `json`, `json2`, `url`, `querify` |
| `raw` | Il valore senza codifica |
| `format([format], ...)` | Formatta un numero o una data (le stringhe vengono riconosciute) |
| `currency([code])` | Formatta un numero con un formatter da `DEF.currencies[code]` (o `DEF.currencies.default`); senza di esso usa due decimali |
| `pluralize(zero, one, few, other)` | Sceglie una parola in base a un numero |
| `empty([text])`, `def([text])` | Il valore, o `text` (predefinito `---`) quando è vuoto |

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