---
title: Helper di Tangular
project: jComponent V20
version: 20.015
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/jcomponent-v20/20-015/reference/tangular-helpers/
updated: 2026-11-18T13:58:19.462Z
---

# Helper di Tangular

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

Un helper segue il valore in un template, come in `{{ price | format(2) }}`, e gli helper possono essere concatenati. Un valore senza helper viene codificato con `encode`. Per scrivere template e registrare helper personalizzati, vedi [Template con Tangular](../../guides/tangular/).

## API

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

Type: `method`

Scrive un campo di un elemento di un elenco di codici.

| 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 del campo.

L'elenco di codici è l'array in `DEF.cl[name]` e l'elemento viene trovato tramite il suo `id`. Quando non viene trovato nulla, l'helper scrive `DEF.empty`, oppure una stringa vuota quando `key` è impostato.

Example: Leggere un elenco di codici
```js
DEF.cl.colors = [{ id: 2, name: 'Red', code: 'R' }];
console.log(Tangular.render("{{ id | cl('colors') }}", { id: 2 })); // Red
console.log(Tangular.render("{{ id | cl('colors', 'code') }}", { id: 2 })); // R
console.log(Tangular.render("{{ id | cl('colors') }}", { id: 9 })); // ---
```

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

Type: `method`

Scrive un elemento di un elenco di codici come etichetta colorata.

| 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'etichetta.

L'helper scrive uno `<span class="ui-clcolor">` con il colore dell'elemento come sfondo, l'icona dell'elemento e il campo. Scrive una stringa vuota quando l'elemento non viene trovato. L'output non viene codificato.

Example: Un'etichetta colorata
```js
DEF.cl.colors = [{ id: 2, name: 'Red', icon: 'ti ti-circle', color: '#f00' }];
console.log(Tangular.render("{{ id | clcolor('colors') }}", { id: 2 })); // <span class="ui-clcolor" style="background:#f00"><i class="ti ti-circle mr5"></i>Red</span>
```

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

Type: `method`

Scrive un elemento di un elenco di codici con la sua 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.

L'icona assume il colore dell'elemento. Un elemento senza icona scrive solo il campo, e un elemento non trovato scrive una stringa vuota. L'output non viene codificato.

Example: Un elemento con un'icona
```js
DEF.cl.colors = [{ id: 1, name: 'Plain' }, { id: 2, name: 'Red', icon: 'ti ti-circle', color: '#f00' }];
console.log(Tangular.render("{{ id | clicon('colors') }}", { id: 2 })); // <i class="ti ti-circle mr5" style="color:#f00"></i>Red
console.log(Tangular.render("{{ id | clicon('colors') }}", { id: 1 })); // Plain
```

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

Type: `method`

Formatta un numero o una stringa numerica con una valuta registrata.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no | `DEF.currency` | Il nome della valuta. |

Returns: `String` Il prezzo formattato.

L'helper usa [currency()](../number/). Un valore di un altro tipo scrive una stringa vuota.

Example: Prezzi
```js
DEF.currencies.eur = value => value.format(2) + ' EUR';
console.log(Tangular.render("{{ price | currency('eur') }}", { price: 5 })); // 5.00 EUR
console.log(Tangular.render("{{ price | currency('eur') }}", { price: '7.5' })); // 7.50 EUR
```

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

Type: `method`

Un alias dell'helper `empty`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | Il testo per un valore vuoto. |
| `raw` | `Boolean` | no | `false` | `true` scrive il valore senza codificarlo. |

Returns: `String` Il valore o il testo.

Example: Testo predefinito
```js
console.log(Tangular.render("{{ name | def('n/a') }}", { name: null })); // n/a
```

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

Type: `method`

Scrive un testo predefinito per un valore vuoto.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | Il testo per un valore vuoto. |
| `raw` | `Boolean` | no | `false` | `true` scrive il valore senza codificarlo. |

Returns: `String` Il valore o il testo.

Ogni valore falsy è considerato vuoto, compreso `0`. Gli altri valori vengono codificati a meno che `raw` non sia `true`. Passare `true` come primo argomento attiva anche `raw`.

Example: Valori vuoti
```js
console.log(Tangular.render('{{ name | empty }}', { name: '' })); // ---
console.log(Tangular.render("{{ name | empty('n/a') }}", { name: '' })); // n/a
console.log(Tangular.render('{{ name | empty }}', { name: '<b>' })); // &lt;b&gt;
console.log(Tangular.render('{{ name | empty(true) }}', { name: '<b>' })); // <b>
```

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

Type: `method`

Codifica un valore per l'output.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no |  | `json` per JSON, `json2` per JSON indentato, `url` o `urlencoded` per `encodeURIComponent()` e `querify` per una stringa di query. |

Returns: `String` Il valore codificato.

Senza `type`, l'helper esegue l'escape di `<`, `>`, `&` e `"`, e scrive una stringa vuota per `null` e `undefined`.

Example: Codifica
```js
console.log(Tangular.render('{{ value | encode }}', { value: '<b>' })); // &lt;b&gt;
console.log(Tangular.render("{{ value | encode('json') }}", { value: { a: 1 } })); // {"a":1}
console.log(Tangular.render("{{ value | encode('url') }}", { value: 'a b' })); // a%20b
console.log(Tangular.render("{{ value | encode('querify') }}", { value: { a: 1, b: 'x y' } })); // ?a=1&b=x%20y
```

### {{ value | format([format], [separator], [decimalSeparator]) }}

Type: `method`

Formatta un numero o una data.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `Number or String` | no |  | Le cifre decimali per un numero, oppure il layout per una data. |
| `separator` | `String` | no |  | Il separatore delle migliaia di un numero. |
| `decimalSeparator` | `String` | no |  | Il separatore decimale di un numero. |

Returns: `String` Il valore formattato.

Per un numero, gli argomenti sono quelli di [format()](../number/), e un numero senza `decimals` viene scritto senza la parte decimale. Per un `Date`, il primo argomento è il layout di [format()](../date/).

Una stringa che contiene una data viene prima convertita e usa `dd.MM.yyyy` per impostazione predefinita, mentre una stringa che contiene un numero viene convertita in numero. `null` e `undefined` scrivono una stringa vuota.

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

Example: Date
```js
var date = new Date(2026, 10, 8, 15, 4);
console.log(Tangular.render("{{ value | format('dd.MM.yyyy HH:mm') }}", { value: date })); // 08.11.2026 15:04
console.log(Tangular.render('{{ value | format }}', { value: '2026-11-08' })); // 08.11.2026
```

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

Type: `method`

Seleziona il testo che corrisponde a un numero.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `zero` | `String` | yes |  | Il testo per 0. |
| `one` | `String` | yes |  | Il testo per 1. |
| `few` | `String` | yes |  | Il testo per i numeri da 2 a 4. |
| `other` | `String` | yes |  | Il testo per gli altri numeri. |

Returns: `String` Il testo selezionato.

Gli argomenti sono quelli di [pluralize()](../number/). Una stringa numerica viene convertita in numero, e un valore vuoto conta come `0`.

Example: Contare gli elementi
```js
var template = "{{ count | pluralize('no items', '# item', '# items', '# items') }}";
console.log(Tangular.render(template, { count: 3 })); // 3 items
console.log(Tangular.render(template, { count: 1 })); // 1 item
console.log(Tangular.render(template, { count: null })); // no items
```

### {{ value | raw }}

Type: `method`

Scrive un valore senza codificarlo.

Returns: `Object` Il valore invariato.

Usalo solo per contenuti che possono essere inseriti come HTML in sicurezza.

Example: Scrivere HTML
```js
console.log(Tangular.render('{{ value | raw }}', { value: '<b>Hi</b>' })); // <b>Hi</b>
console.log(Tangular.render('{{ value }}', { value: '<b>Hi</b>' })); // &lt;b&gt;Hi&lt;/b&gt;
```
