String Templates
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:
You can use as many placeholders as you like in one template:
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:
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).
For a list of three items, this produces:
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
42prints as42; a yes/no value prints astrueorfalse. - 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.