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

# Tangular helpers

> The helpers available in every Tangular template for encoding, formatting and reading code lists.

A helper follows the value in a template, as in `{{ price | format(2) }}`, and helpers can be chained. A value with no helper is encoded with `encode`. To write templates and register custom helpers, see [Templates with Tangular](../../guides/tangular/).

## API

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

Type: `method`

Writes a field of an item in a code list.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The code list name. |
| `key` | `String` | no | `name` | The field to write. |

Returns: `String` The value of the field.

The code list is the array in `DEF.cl[name]`, and the item is found by its `id`. When nothing is found, the helper writes `DEF.empty`, or an empty string when `key` is set.

Example: Reading a code list
```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`

Writes an item of a code list as a colored label.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The code list name. |
| `key` | `String` | no | `name` | The field to write. |

Returns: `String` The HTML of the label.

The helper writes a `<span class="ui-clcolor">` with the item color as its background, the item icon and the field. It writes an empty string when the item is not found. The output is not encoded.

Example: A colored label
```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`

Writes an item of a code list with its icon.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The code list name. |
| `key` | `String` | no | `name` | The field to write. |

Returns: `String` The HTML of the item.

The icon takes the item color. An item without an icon writes only the field, and an item that is not found writes an empty string. The output is not encoded.

Example: An item with an icon
```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`

Formats a number or a numeric string with a registered currency.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | no | `DEF.currency` | The currency name. |

Returns: `String` The formatted price.

The helper uses [currency()](../number/). A value of another type writes an empty string.

Example: Prices
```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`

An alias of the `empty` helper.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | The text for an empty value. |
| `raw` | `Boolean` | no | `false` | `true` writes the value without encoding. |

Returns: `String` The value or the text.

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

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

Type: `method`

Writes a default text for an empty value.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | The text for an empty value. |
| `raw` | `Boolean` | no | `false` | `true` writes the value without encoding. |

Returns: `String` The value or the text.

Every falsy value is empty, including `0`. Other values are encoded unless `raw` is `true`. Passing `true` as the first argument also turns on `raw`.

Example: Empty values
```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`

Encodes a value for output.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String` | no |  | `json` for JSON, `json2` for indented JSON, `url` or `urlencoded` for `encodeURIComponent()`, and `querify` for a query string. |

Returns: `String` The encoded value.

Without `type`, the helper escapes `<`, `>`, `&` and `"`, and writes an empty string for `null` and `undefined`.

Example: Encoding
```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`

Formats a number or a date.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `Number or String` | no |  | The decimal places for a number, or the layout for a date. |
| `separator` | `String` | no |  | The thousands separator of a number. |
| `decimalSeparator` | `String` | no |  | The decimal separator of a number. |

Returns: `String` The formatted value.

For a number, the arguments are those of [format()](../number/), and a number without `decimals` is written without its decimal part. For a `Date`, the first argument is the layout of [format()](../date/).

A string that holds a date is converted first and uses `dd.MM.yyyy` by default, and a string that holds a number is converted to a number. `null` and `undefined` write an empty string.

Example: Numbers
```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: Dates
```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`

Selects the text that matches a number.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `zero` | `String` | yes |  | The text for 0. |
| `one` | `String` | yes |  | The text for 1. |
| `few` | `String` | yes |  | The text for numbers from 2 to 4. |
| `other` | `String` | yes |  | The text for other numbers. |

Returns: `String` The selected text.

The arguments are those of [pluralize()](../number/). A numeric string is converted to a number, and an empty value counts as `0`.

Example: Counting items
```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`

Writes a value without encoding.

Returns: `Object` The unchanged value.

Use it only for content that is safe to insert as HTML.

Example: Writing 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;
```
