---
title: Tangular
project: Total.js V5
version: 0.0.20
section: reference
language: sk
license: MIT
url: https://totaljs.es/docs/sk/total-js-v5/0-0-20/reference/tangular/
updated: 2026-11-18T16:56:54.572Z
---

# Tangular

> Tangular.compile(), Tangular.render(), Tangular.register() a Tangular.helpers.

## API

### Tangular.compile(template, [tagbeg], [tagend])

Type: `method`

Skompiluje šablónu Tangular do funkcie.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Šablóna. |
| `tagbeg` | `String` | no | `'{{'` | Začiatok príkazu. |
| `tagend` | `String` | no | `'}}'` | Koniec príkazu. |

Returns: `Function` `function(model, [repository], [helpers])`.

Funkcia je `template(model, [repository], [helpers])` a vracia reťazec. Názvy v šablóne sa čítajú z modelu, `$` je repository a `$index` index v cykle. Chyby počas renderovania sa vypíšu do konzoly. `tagbeg` a `tagend` nahradia `{{` a `}}` (ako časti regulárneho výrazu). Príkazy sú opísané vo [Views](../../guides/views/#templates).

Example: Jednorazová kompilácia
```js
var row = Tangular.compile('<tr><td>{{ name }}</td><td>{{ price | format(2) }}</td></tr>');
var html = items.map(item => row(item)).join('');
```

Example: Lokálne pomocné funkcie
```js
var t = Tangular.compile('{{ name | badge }}');
t({ name: 'New' }, null, { badge: function(value) { return '<span class="badge">' + value + '</span>'; } });
```

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

Type: `method`

Skompiluje a vyrenderuje šablónu jedným volaním.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | Šablóna. |
| `model` | `Object` | no | `{}` | Model. |
| `repository` | `Object` | no |  | Dostupné ako `$`. |
| `helpers` | `Object` | no |  | Pomocné funkcie pre toto volanie. |

Returns: `String` Výstup.

Pre šablóny, ktoré renderuješ často, použi `Tangular.compile()`.

Example: Renderovanie
```js
Tangular.render('Hello {{ name }}!', { name: 'Peter' }); // 'Hello Peter!'
```

### Tangular.register(name, fn)

Type: `method`

Pridá pomocnú funkciu pre všetky šablóny Tangular.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Názov pomocnej funkcie. |
| `fn` | `Function` | yes |  | `function(value, [args...])`. |

Returns: `Object` Tangular, na reťazenie.

Pomocná funkcia sa volá ako `fn.call(model, value, ...arguments)`: `{{ price | money('EUR') }}` zavolá `money(price, 'EUR')`. Chýbajúca pomocná funkcia vypíše varovanie a vráti hodnotu.

Example: Pomocná funkcia
```js
Tangular.register('money', function(value, currency) {
	return value.format(2) + ' ' + (currency || 'EUR');
});
```

### Tangular.helpers

Type: `property`

Vstavané pomocné funkcie Tangularu, dostupné aj ako globálny `Thelpers`.

Returns: `Object`

| Pomocná funkcia | Popis |
| --- | --- |
| `encode([type])` | Zakóduje pre HTML; používa sa pre každú hodnotu bez `raw`. Typy: `json`, `json2`, `url`, `querify` |
| `raw` | Hodnota bez kódovania |
| `format([format], ...)` | Naformátuje číslo alebo dátum (reťazce sa rozpoznajú) |
| `currency([code])` | Naformátuje číslo formátovačom z `DEF.currencies[code]` (alebo `DEF.currencies.default`); bez neho použije dve desatinné miesta |
| `pluralize(zero, one, few, other)` | Vyberie slovo podľa čísla |
| `empty([text])`, `def([text])` | Hodnota, alebo `text` (predvolene `---`), keď je prázdna |

Example: Použitie
```js
Tangular.render('{{ count | pluralize(\'no items\', \'# item\', \'# items\', \'# items\') }}', { count: 3 });
```
