---
title: Tangular
project: jComponent V20
version: 20.016
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v20/20-016/reference/tangular/
updated: 2026-12-02T17:12:55.816Z
---

# Tangular

> Le funzioni che compilano e renderizzano i template e registrano gli helper.

`Tangular` è il motore di template incluso nella libreria, e `Ta` è un altro nome dello stesso oggetto. La sintassi dei template è spiegata nella guida [Template con Tangular](../../guides/tangular/), mentre gli helper disponibili in ogni template sono elencati in [Helper di Tangular](../tangular-helpers/).

## API

### Tangular.compile(template, [begin], [end])

Type: `method`

Compila un template in una funzione.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Il template. |
| `begin` | `String` | no | `{{` | Il testo che apre un tag. |
| `end` | `String` | no | `}}` | Il testo che chiude un tag. |

Returns: `Function` Una funzione `(model, [repository], [helpers])` che restituisce il testo renderizzato.

La funzione restituita accetta gli stessi argomenti di `Tangular.render()`, senza il template. `begin` ed `end` vengono usati solo insieme. Sono testo semplice, mentre un valore con una barra rovesciata viene interpretato come parte di un'espressione regolare.

Un errore durante il rendering di un template viene scritto nella console e la funzione restituisce `undefined`. Un errore nella sintassi del template viene invece lanciato durante la compilazione.

Example: Renderizza più volte
```js
var template = Tangular.compile('Hello {{ name }}!');

console.log(template({ name: 'Ann' })); // Hello Ann!
console.log(template({ name: 'Bob' })); // Hello Bob!
```

Example: Altri delimitatori
```js
var template = Tangular.compile('[[ name ]] and {{ other }}', '[[', ']]');

console.log(template({ name: 'Ann' })); // Ann and {{ other }}
```

### Tangular.helpers

Type: `property`

Gli helper disponibili in ogni template, per nome.

Returns: `Object` Gli helper disponibili in ogni template, per nome.

La variabile globale `Thelpers` è lo stesso oggetto. Una funzione assegnata a esso è un helper, proprio come con `Tangular.register()`. Gli helper si possono chiamare anche dal codice.

Example: Aggiungi e chiama un helper
```js
Thelpers.initials = function(value) {
	return value.split(' ').map(word => word.charAt(0)).join('');
};

console.log(Tangular.render('{{ name | initials }}', { name: 'Ann Lee' })); // AL
console.log(Thelpers.encode('<b>')); // &lt;b&gt;
console.log(Thelpers === Tangular.helpers); // true
```

### Tangular.register(name, callback)

Type: `method`

Registra un helper per tutti i template.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome usato nei template. |
| `callback` | `Function` | yes |  | Una funzione che riceve il valore e gli argomenti scritti nel template e restituisce il testo da scrivere. |

Returns: `Object` L'oggetto `Tangular`, così le chiamate si possono concatenare.

Dentro la callback, `this` è il modello. Il risultato non viene codificato.

Example: Registra un helper
```js
Tangular.register('wrap', function(value, before, after) {
	return before + value + after;
});

console.log(Tangular.render('{{ name | wrap("[", "]") }}', { name: 'Ann' })); // [Ann]
console.log(Tangular.render('{{ wrap("a", "b", "c") }}')); // bac
```

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

Type: `method`

Compila un template e lo renderizza.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Il template. |
| `model` | `Object` | no | `{}` | I valori disponibili nel template per nome. |
| `repository` | `Object` | no | `{}` | Altri valori, disponibili come `$`. |
| `helpers` | `Object` | no |  | Helper per questa chiamata. Hanno la precedenza su quelli registrati. |

Returns: `String` Il testo renderizzato, oppure `undefined` dopo un errore.

Il template compilato viene conservato in memoria, quindi renderizzare di nuovo lo stesso testo non lo compila un'altra volta.

Example: Renderizza un template
```js
console.log(Tangular.render('Hello {{ name }}', { name: 'Ann' })); // Hello Ann
console.log(Tangular.render('{{ $.title }}: {{ name }}', { name: 'Ann' }, { title: 'User' })); // User: Ann
```

Example: Helper per una sola chiamata
```js
var helpers = { shout: value => value + '!' };

console.log(Tangular.render('{{ name | shout }}', { name: 'Ann' }, null, helpers)); // Ann!
```

### Tangular.version

Type: `property`

La versione del motore di template.

Returns: `String` La versione del motore di template.

Example: Leggi la versione
```js
console.log(Tangular.version); // v5.0.6
```
