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.
data.template 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.
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
before it that builds exactly the object the template reads:
{{ ({ 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:
{{ $('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 |
{{#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}}Escaping
Double braces escape HTML characters (&, <, >, quotes): {{name}} renders Ana & Co for Ana & Co. Use
triple braces to insert a value as it is, for example a fragment of HTML you built yourself:
{{{signature_html}}}A missing field renders as an empty string. To write literal double braces, escape them with a backslash: \{{name}}.