---
title: Helper di Tangular
project: jComponent V19
version: 19.194
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v19/19-194/reference/tangular-helpers/
updated: 2026-11-18T13:58:29.465Z
---

# Helper di Tangular

> Gli helper disponibili nei template Tangular per codificare, formattare e leggere gli elenchi di codici.

Un helper trasforma un valore in un template: `{{ value | helper(arguments) }}`. Questi helper si trovano nell'oggetto globale `Thelpers`, quindi puoi chiamarli anche dal codice passando il valore come primo argomento. Un valore senza helper viene codificato automaticamente in HTML; un valore con un helper viene scritto così come l'helper lo restituisce. [Template con Tangular](../../guides/tangular/) spiega la sintassi e come aggiungere i tuoi helper.

## API

### {{ id | cl(name, [key]) }}

Type: `method`

Scrive un valore dell'elemento dell'elenco di codici con l'identificatore indicato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'elenco di codici. |
| `key` | `String` | no | `'name'` | Il campo da scrivere. |

Returns: `String` Il valore dell'elemento.

L'elenco di codici viene letto da `DEF.cl[name]` e i suoi elementi vengono confrontati tramite il campo `id`. Senza `key`, l'helper scrive il campo `name`, oppure `DEF.empty` quando l'elemento non esiste. Con `key`, un elemento mancante scrive un testo vuoto. L'output non viene codificato in HTML.

Example: Leggi un elenco di codici
```js
DEF.cl.colors = [
	{ id: 1, name: 'Red', icon: 'ti ti-circle', color: '#f00' },
	{ id: 2, name: 'Blue' }
];

'{{ id | cl("colors") }}'.render({ id: 1 }); // "Red"
'{{ id | cl("colors", "color") }}'.render({ id: 1 }); // "#f00"
'{{ id | cl("colors") }}'.render({ id: 9 }); // "---"
```

### {{ id | clcolor(name, [key]) }}

Type: `method`

Scrive un elemento dell'elenco di codici come `<span>` colorato.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'elenco di codici. |
| `key` | `String` | no | `'name'` | Il campo da scrivere. |

Returns: `String` L'HTML dell'elemento.

L'elemento ha la classe `ui-clcolor`. Il campo `color` dell'elemento imposta lo sfondo e il campo `icon` aggiunge un'icona. Un elemento mancante scrive un testo vuoto. L'output non viene codificato in HTML.

Example: Un'etichetta colorata
```js
DEF.cl.colors = [
	{ id: 1, name: 'Red', icon: 'ti ti-circle', color: '#f00' },
	{ id: 2, name: 'Blue' }
];

'{{ id | clcolor("colors") }}'.render({ id: 1 }); // "<span class=\"ui-clcolor\" style=\"background:#f00\"><i class=\"ti ti-circle mr5\"></i>Red</span>"
'{{ id | clcolor("colors") }}'.render({ id: 2 }); // "<span class=\"ui-clcolor\">Blue</span>"
```

### {{ id | clicon(name, [key]) }}

Type: `method`

Scrive un elemento dell'elenco di codici con la relativa icona.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'elenco di codici. |
| `key` | `String` | no | `'name'` | Il campo da scrivere. |

Returns: `String` L'HTML dell'elemento.

Il campo `icon` aggiunge un elemento `<i>` e il campo `color` imposta il colore dell'icona. Un elemento mancante scrive un testo vuoto. L'output non viene codificato in HTML.

Example: Un elemento con un'icona
```js
DEF.cl.colors = [
	{ id: 1, name: 'Red', icon: 'ti ti-circle', color: '#f00' },
	{ id: 2, name: 'Blue' }
];

'{{ id | clicon("colors") }}'.render({ id: 1 }); // "<i class=\"ti ti-circle mr5\" style=\"color:#f00\"></i>Red"
'{{ id | clicon("colors") }}'.render({ id: 2 }); // "Blue"
```

### {{ value | currency([code]) }}

Type: `method`

Formatta come valuta un numero o un testo numerico.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `String` | no |  | Il codice della valuta registrato in `DEF.currencies`. |

Returns: `String` L'importo formattato.

L'helper chiama [currency()](../number/#currency). I valori che non sono numeri o testi scrivono un testo vuoto.

Example: Scrivi un importo
```js
DEF.currencies.eur = value => value.format(2) + ' EUR';

'{{ price | currency("eur") }}'.render({ price: 1234.5 }); // "1 234.50 EUR"
'{{ price | currency("eur") }}'.render({ price: '1234,5' }); // "1 234.50 EUR"
'{{ price | currency("eur") }}'.render({ price: null }); // ""
```

### {{ value | def([text]) }}

Type: `method`

Scrive il valore, oppure un sostituto quando il valore è vuoto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | Il testo sostitutivo. |

Returns: `String` Il valore codificato o il sostituto.

Ogni valore falsy è considerato vuoto, compreso `0`. Il valore viene codificato in HTML. Il sostituto predefinito è `DEF.empty`, cioè `---`. `empty` è un altro nome di questo helper.

Example: Sostituisci un valore vuoto
```js
'{{ name | def }}'.render({ name: '' }); // "---"
'{{ name | def("unknown") }}'.render({}); // "unknown"
'{{ name | def }}'.render({ name: '<b>' }); // "&lt;b&gt;"
'{{ count | def }}'.render({ count: 0 }); // "---"
```

### {{ value | empty([text]) }}

Type: `method`

Un altro nome dell'helper [def](#def).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | Il testo sostitutivo. |

Returns: `String` Il valore codificato o il sostituto.

Example: Sostituisci un valore vuoto
```js
'{{ name | empty }}'.render({}); // "---"
'{{ name | empty("n/a") }}'.render({ name: 'Ann' }); // "Ann"
```

### {{ value | encode([type]) }}

Type: `method`

Codifica il valore per HTML, JSON o un URL.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String or Function` | no |  | Il tipo di codifica. |

Returns: `String` Il valore codificato.

Senza `type`, i caratteri `<`, `>`, `&` e `"` vengono scritti come entità HTML, e `null` o `undefined` scrivono un testo vuoto.

| Tipo | Output |
| --- | --- |
| `'json'` | JSON |
| `'json2'` | JSON indentato con tabulazioni |
| `'url'`, `'urlencoded'` | Un valore codificato per URL |
| `'querify'` | Una stringa di query costruita con `QUERIFY()` |
| Funzione | Il risultato di `function(value)` |

Example: Tipi di codifica
```js
'{{ value | encode }}'.render({ value: '<b>' }); // "&lt;b&gt;"
'{{ value | encode("json") }}'.render({ value: { id: 1 } }); // "{\"id\":1}"
'{{ value | encode("url") }}'.render({ value: 'a b&c' }); // "a%20b%26c"
'{{ value | encode("querify") }}'.render({ value: { page: 1, q: 'x y' } }); // "?page=1&q=x%20y"
```

### {{ value | format([format], [a], [b]) }}

Type: `method`

Formatta un numero, una data o un testo che ne contiene uno.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `Number or String` | no |  | Il numero di decimali o il formato della data. |
| `a` | `Object` | no |  | Il separatore delle migliaia per i numeri, oppure `utc` per le date. |
| `b` | `String` | no |  | Il separatore decimale per i numeri. |

Returns: `String` Il valore formattato.

Gli argomenti dipendono dal valore:

| Valore | Argomenti | Risultato |
| --- | --- | --- |
| Numero | `decimals`, `separator`, `decimalSeparator` | [format() di Number](../number/#format). Senza `decimals`, non vengono scritti decimali. |
| Data | `format`, `utc` | [format() di Date](../date/#format) |
| Testo con una data | `format` | La data, per impostazione predefinita come `dd.MM.yyyy` |
| Testo numerico | `decimals`, `separator`, `decimalSeparator` | Il numero, che mantiene i decimali quando manca `decimals` |

Un testo è considerato una data quando contiene due punti, uno spazio, la lettera `T`, oppure più di un `-` o `.`. `null` e `undefined` scrivono un testo vuoto.

Example: Numeri
```js
'{{ price | format(2) }}'.render({ price: 1234.5 }); // "1 234.50"
'{{ price | format }}'.render({ price: 1234.5 }); // "1 234"
'{{ price | format(2, ",", ".") }}'.render({ price: 1234.5 }); // "1,234.50"
```

Example: Date
```js
var date = new Date(2026, 10, 18);

'{{ date | format("dd.MM.yyyy") }}'.render({ date: date }); // "18.11.2026"
'{{ date | format }}'.render({ date: date }); // "2026-11-18"
```

Example: Valori testuali
```js
Thelpers.format('2026-11-18'); // "18.11.2026"
Thelpers.format('2026-11-18', 'yyyy/MM'); // "2026/11"
Thelpers.format('1234.5'); // "1 234.5"
Thelpers.format('1234,5', 2); // "1 234.50"
```

### {{ value | pluralize(zero, one, few, other) }}

Type: `method`

Sceglie un testo in base alla grandezza di un numero.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `zero` | `String or Array` | yes |  | Il testo per 0, oppure tutte e quattro le forme. |
| `one` | `String` | yes |  | Il testo per 1. |
| `few` | `String` | yes |  | Il testo per i numeri maggiori di 1 e minori di 5. |
| `other` | `String` | yes |  | Il testo per tutti gli altri numeri. |

Returns: `String` Il testo scelto.

L'helper chiama [pluralize()](../number/#pluralize). Un valore testuale viene prima convertito in numero: gli spazi vengono rimossi e una virgola viene letta come separatore decimale.

Example: Scegli una forma
```js
var template = '{{ count | pluralize("no items", "# item", "# items", "# items") }}';

template.render({ count: 0 }); // "no items"
template.render({ count: 1 }); // "1 item"
template.render({ count: 7 }); // "7 items"
```

### {{ value | raw }}

Type: `method`

Scrive il valore senza codifica HTML.

Returns: `Object` Il valore invariato.

Usa questo helper solo con contenuti attendibili.

Example: Scrivi HTML
```js
'{{ html | raw }}'.render({ html: '<b>Hello</b>' }); // "<b>Hello</b>"
```
