String Templates

View as Markdown

A string template is text with placeholders that get filled in when a workflow runs. You write ordinary text and mark the spots where a value should go with {{ }}. When the step runs, each placeholder is replaced with the real value. Templates are the natural choice any time you are building text: an email body, a subject line, a message, or a URL.

The basics

Put an expression inside the double braces and it is replaced with its value:

Hello, {{node.contact.first_name}}!

You can use as many placeholders as you like in one template:

{{node.contact.first_name}} {{node.contact.last_name}} has {{node.account.points}} points.

The placeholder does not have to be a simple value. Anything you can write as an expression works, including a small calculation or a choice between two options:

Your score is {{node.score.value * 100}}% ({{node.score.value >= 0.7 ? "Pass" : "Fail"}}).

Need a literal {{ in your text, rather than a placeholder? Write \{{ and it will appear as {{ in the output.

Repeating text for a list

Sometimes you want to produce one line of text per item in a list, like a line-item summary or a bulleted digest. An {{each}} block does that: it repeats the text between {{each ...}} and {{end}} once for every item in a list.

Inside the block, refer to the current item and its position by adding ._each_.item and ._each_.index to the list’s path. So if you are looping over node.order.items, the current item is node.order.items._each_.item and its position is node.order.items._each_.index (counting from zero, so add 1 for a friendly, human-readable number).

Here is your order:
{{each node.order.items}}
{{node.order.items._each_.index + 1}}. {{node.order.items._each_.item.name}} (qty: {{node.order.items._each_.item.quantity}})
{{end}}
Thank you for your order!

For a list of three items, this produces:

Here is your order:
1. Widget A (qty: 3)
2. Widget B (qty: 7)
3. Gadget C (qty: 1)
Thank you for your order!

An {{each}} block builds text. If instead you need to run a set of steps for every item in a list, such as sending a separate email to each contact, use the For Each node. A rough rule: reach for {{each}} to assemble a report, reach for For Each to take an action per item.

Good to know

  • Everything becomes text. Whatever a placeholder holds is turned into text for the output. A number like 42 prints as 42; a yes/no value prints as true or false.
  • Spaces inside the braces do not matter. {{ node.value }} and {{node.value}} mean the same thing.
  • The list in an {{each}} block must be a plain reference to a list a step produced, not a calculation. If you need to filter or reshape a list first, do that in an earlier step (for example a Data Transform) and point the block at that step’s output.