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

# Tangular helpers

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

A helper transforms a value in a template: `{{ value | helper(arguments) }}`. These helpers live in the global object `Thelpers`, so they can also be called from code with the value as the first argument. A value without a helper is HTML-encoded automatically; a value with a helper is written as the helper returns it. [Templates with Tangular](../../guides/tangular/) explains the syntax and how to add your own helpers.

## API

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

Type: `method`

Writes a value of the code list item with the given identifier.

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

Returns: `String` The value of the item.

The code list is read from `DEF.cl[name]`, and its items are matched by the field `id`. Without `key`, the helper writes the field `name`, or `DEF.empty` when the item does not exist. With `key`, a missing item writes an empty text. The output is not HTML-encoded.

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

Writes a code list item as a colored `<span>`.

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

Returns: `String` The HTML of the item.

The element has the class `ui-clcolor`. The `color` field of the item sets its background and the `icon` field adds an icon. A missing item writes an empty text. The output is not HTML-encoded.

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

Writes a code list item with its icon.

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

Returns: `String` The HTML of the item.

The `icon` field adds an `<i>` element, and the `color` field sets the color of the icon. A missing item writes an empty text. The output is not HTML-encoded.

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

Formats a number or a numeric text as a currency.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `code` | `String` | no |  | The currency code registered in `DEF.currencies`. |

Returns: `String` The formatted amount.

The helper calls [currency()](../number/#currency). Values that are not numbers or texts write an empty text.

Example: Write an amount
```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`

Writes the value, or a replacement when the value is empty.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | The replacement text. |

Returns: `String` The encoded value or the replacement.

Every falsy value counts as empty, including `0`. The value is HTML-encoded. The replacement defaults to `DEF.empty`, which is `---`. `empty` is another name for this helper.

Example: Replace an empty value
```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`

Another name for the helper [def](#def).

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `text` | `String` | no | `DEF.empty` | The replacement text. |

Returns: `String` The encoded value or the replacement.

Example: Replace an empty value
```js
'{{ name | empty }}'.render({}); // "---"
'{{ name | empty("n/a") }}'.render({ name: 'Ann' }); // "Ann"
```

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

Type: `method`

Encodes the value for HTML, JSON or a URL.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `type` | `String or Function` | no |  | The type of encoding. |

Returns: `String` The encoded value.

Without `type`, the characters `<`, `>`, `&` and `"` are written as HTML entities and `null` or `undefined` writes an empty text.

| Type | Output |
| --- | --- |
| `'json'` | JSON |
| `'json2'` | JSON indented with tabs |
| `'url'`, `'urlencoded'` | A URL-encoded value |
| `'querify'` | A query string built with `QUERIFY()` |
| Function | The result of `function(value)` |

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

Formats a number, a date or a text that holds one of them.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `format` | `Number or String` | no |  | The number of decimals, or the date format. |
| `a` | `Object` | no |  | The thousands separator for numbers, or `utc` for dates. |
| `b` | `String` | no |  | The decimal separator for numbers. |

Returns: `String` The formatted value.

The arguments depend on the value:

| Value | Arguments | Result |
| --- | --- | --- |
| Number | `decimals`, `separator`, `decimalSeparator` | [Number format()](../number/#format). Without `decimals`, no decimals are written. |
| Date | `format`, `utc` | [Date format()](../date/#format) |
| Text with a date | `format` | The date, by default as `dd.MM.yyyy` |
| Numeric text | `decimals`, `separator`, `decimalSeparator` | The number, which keeps its decimals when `decimals` is missing |

A text counts as a date when it contains a colon, a space, the letter `T`, or more than one `-` or `.`. `null` and `undefined` write an empty text.

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

Chooses a text by the size of a number.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `zero` | `String or Array` | yes |  | The text for 0, or all four forms. |
| `one` | `String` | yes |  | The text for 1. |
| `few` | `String` | yes |  | The text for numbers greater than 1 and lower than 5. |
| `other` | `String` | yes |  | The text for all other numbers. |

Returns: `String` The chosen text.

The helper calls [pluralize()](../number/#pluralize). A text value is converted to a number first; spaces are removed and a comma is read as a decimal separator.

Example: Choose a form
```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`

Writes the value without HTML encoding.

Returns: `Object` The unchanged value.

Use this helper only with trusted content.

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