# Handlebars

> How data.template renders text with Handlebars — what data the template sees, the built-in helpers you can use, HTML escaping, and how later nodes read the rendered text.

Source: https://docs.sommatic.ai/en/expressions/handlebars/ (updated 2026-11-26)

[`data.template`](https://docs.sommatic.ai/en/nodes/data.template.md) renders a text — an email body, a message, a document — from a Handlebars
template. Use it when the text is long and mostly fixed, with values and repeated blocks in between.

## What the template sees

The `template` field is read by Handlebars, not by the expression engine. It renders against the **input of the node**
(the output of the previous node), and nothing else: fields are named directly, and run variables such as `$json`,
`$execution` or `$('…')` are not available.

```handlebars
Hello {{customer.first_name}},

We received your request {{request_id}} on {{received_at}}.
```

When the template needs data from several nodes or from the run, put a [`data.transform`](https://docs.sommatic.ai/en/nodes/data.transform.md)
before it that builds exactly the object the template reads:

```javascript
{{ ({ customer: $('Find customer').item.json, request_id: $execution.id, received_at: $now.setZone('America/Bogota').toFormat('yyyy-LL-dd HH:mm') }) }}
```

## Output

The node returns its input plus a `text` field with the rendered result. Later nodes read it like this:

```javascript
{{ $('Render email').item.json.text }}
```

## Built-in helpers

Only the helpers that ship with Handlebars are available:

| Helper        | Use                                                                      |
| ------------- | ------------------------------------------------------------------------ |
| `if` / `else` | Render a block when a value is truthy                                    |
| `unless`      | Render a block when a value is falsy                                     |
| `each`        | Repeat a block for every element of a list (`@index`, `@first`, `@last`) |
| `with`        | Change the context to a nested object                                    |
| `lookup`      | Read a key whose name is in another field                                |
| `log`         | Write a value to the log                                                 |

```handlebars
{{#if vip}}Priority customer{{else}}Standard customer{{/if}}

{{#each items}}
- {{sku}} × {{qty}}{{#unless @last}},{{/unless}}
{{/each}}

{{#with customer}}{{first_name}} {{last_name}}{{/with}}

{{lookup labels status}}
```

> **Warning: No comparison helpers**
>
> Helpers such as `eq`, `gt` or `and` do not exist: a template that calls one fails with `Missing helper` and the node
> leaves through `error`. Compute the boolean before the template, for example `is_open` in a `data.transform`, and
> use `{{#if is_open}}`.

## Escaping

Double braces escape HTML characters (`&`, `<`, `>`, quotes): `{{name}}` renders `Ana &amp; Co` for `Ana & Co`. Use
triple braces to insert a value as it is, for example a fragment of HTML you built yourself:

```handlebars
{{{signature_html}}}
```

A missing field renders as an empty string. To write literal double braces, escape them with a backslash: `\{{name}}`.

## Next steps

- [data.template](https://docs.sommatic.ai/en/nodes/data.template.md): Configuration and ports of the template node.
- [Recipes](https://docs.sommatic.ai/en/expressions/recipes.md): Expressions to prepare the data a template reads.
