---
title: Tangular
project: jComponent V20
version: 20.016
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/jcomponent-v20/20-016/reference/tangular/
updated: 2026-12-02T17:12:55.816Z
---

# Tangular

> The functions that compile and render templates and register helpers.

`Tangular` is the template engine included in the library, and `Ta` is another name of the same object. The syntax of the templates is explained in the guide [Templates with Tangular](../../guides/tangular/), and the helpers available in every template are listed in [Tangular helpers](../tangular-helpers/).

## API

### Tangular.compile(template, [begin], [end])

Type: `method`

Compiles a template to a function.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | The template. |
| `begin` | `String` | no | `{{` | The text that opens a tag. |
| `end` | `String` | no | `}}` | The text that closes a tag. |

Returns: `Function` A function `(model, [repository], [helpers])` that returns the rendered text.

The returned function takes the same arguments as `Tangular.render()`, without the template. `begin` and `end` are used only together. They are plain text, and a value with a backslash is taken as a part of a regular expression.

An error while a template renders is written to the console and the function returns `undefined`. An error in the syntax of the template is thrown while it is compiled.

Example: Render several times
```js
var template = Tangular.compile('Hello {{ name }}!');

console.log(template({ name: 'Ann' })); // Hello Ann!
console.log(template({ name: 'Bob' })); // Hello Bob!
```

Example: Other delimiters
```js
var template = Tangular.compile('[[ name ]] and {{ other }}', '[[', ']]');

console.log(template({ name: 'Ann' })); // Ann and {{ other }}
```

### Tangular.helpers

Type: `property`

The helpers available in every template, by name.

Returns: `Object` The helpers available in every template, by name.

The global variable `Thelpers` is the same object. A function assigned to it is a helper, in the same way as with `Tangular.register()`. The helpers can also be called from code.

Example: Add and call a helper
```js
Thelpers.initials = function(value) {
	return value.split(' ').map(word => word.charAt(0)).join('');
};

console.log(Tangular.render('{{ name | initials }}', { name: 'Ann Lee' })); // AL
console.log(Thelpers.encode('<b>')); // &lt;b&gt;
console.log(Thelpers === Tangular.helpers); // true
```

### Tangular.register(name, callback)

Type: `method`

Registers a helper for all templates.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name used in the templates. |
| `callback` | `Function` | yes |  | A function that receives the value and the arguments written in the template, and returns the text to write. |

Returns: `Object` The `Tangular` object, so calls can be chained.

Inside the callback, `this` is the model. The result is not encoded.

Example: Register a helper
```js
Tangular.register('wrap', function(value, before, after) {
	return before + value + after;
});

console.log(Tangular.render('{{ name | wrap("[", "]") }}', { name: 'Ann' })); // [Ann]
console.log(Tangular.render('{{ wrap("a", "b", "c") }}')); // bac
```

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

Type: `method`

Compiles a template and renders it.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `template` | `String` | yes |  | The template. |
| `model` | `Object` | no | `{}` | The values available in the template by name. |
| `repository` | `Object` | no | `{}` | More values, available as `$`. |
| `helpers` | `Object` | no |  | Helpers for this call. They have priority over the registered ones. |

Returns: `String` The rendered text, or `undefined` after an error.

The compiled template is kept in memory, so rendering the same text again does not compile it again.

Example: Render a template
```js
console.log(Tangular.render('Hello {{ name }}', { name: 'Ann' })); // Hello Ann
console.log(Tangular.render('{{ $.title }}: {{ name }}', { name: 'Ann' }, { title: 'User' })); // User: Ann
```

Example: Helpers for one call
```js
var helpers = { shout: value => value + '!' };

console.log(Tangular.render('{{ name | shout }}', { name: 'Ann' }, null, helpers)); // Ann!
```

### Tangular.version

Type: `property`

The version of the template engine.

Returns: `String` The version of the template engine.

Example: Read the version
```js
console.log(Tangular.version); // v5.0.6
```
