The #each block helper iterates over an array or object, rendering the block once for each element. Use it to output repeated content from a list of records, names, or values within a flow.
Syntax
{{#each field}} {{this}} {{/each}}
field -- The array or object to iterate over. Required. In integrator.io, arrays must be referenced as an absolute path in the Resource path field when used as the top-level context.
Built-in variables
These variables are available inside any #each block:
| Variable | Description |
|---|---|
{{this}} |
The current element's value |
{{@index}} |
The current element's zero-based position in the array |
{{@key}} |
The current key name (objects) or index (arrays) |
{{@first}} |
true for the first iteration. Available for arrays and objects. |
{{@last}} |
true for the last iteration. Available for arrays only. |
Examples
Iterate over a simple array
{{#each people}}{{this}}; {{/each}}
Input:
{
"people": [
"Bertram Gilfoyle",
"Erlich Bachman",
"Jin Yang"
]
}
Output: Bertram Gilfoyle; Erlich Bachman; Jin Yang;
The semicolon and space after {{this}} add punctuation between each value in the output.
Iterate over an array of objects
{{#each fields.names}}{{#each this}} Employee {{@key}}: {{this}}
{{/each}}{{/each}}
Input:
{
"fields": {
"names": [
{"name1": "Stacy"},
{"name2": "Lance"},
{"name3": "Bernice"}
]
}
}
Output:
Employee name1: Stacy Employee name2: Lance Employee name3: Bernice
The outer #each iterates over the names array. The inner #each this iterates over the key-value pairs within each object, exposing {{@key}} (the key name) and {{this}} (the value).
Reference the loop index with @index
{{#each fields.rights}}
{{@index}}: {{this}}
{{/each}}
Input:
{
"fields": {
"rights": ["system", "admin", "editor", "contributor", "viewer", "vendor"]
}
}
Output:
0: system 1: admin 2: editor 3: contributor 4: viewer 5: vendor
Reference keys with @key
{{#each fields.rights}}{{@key}}:{{this}}; {{/each}}
Same input as above.
Output: 0:system; 1:admin; 2:editor; 3:contributor; 4:viewer; 5:vendor;
When iterating over an array, {{@key}} returns the numeric index. When iterating over an object, it returns the key name.
Access characters by index using block parameters
Use the as |item| syntax to declare a named reference for each element, then access individual characters by their index position (zero-based).
{{#each inventoryItems as |item|}}
{{item.[0]}}: {{item.[10]}}
{{/each}}
Input:
{
"inventoryItems": {
"X": "1001 text a",
"Y": "2002 text b",
"Z": "3003 text c"
}
}
Output:
1: a 2: b 3: c
Usage notes
- In integrator.io, arrays used as the top-level iteration source must be referenced as an absolute path in the Resource path field. If the context is an object (key-value pair), no path configuration is needed.
-
{{@first}}and{{@last}}mark the first and last iterations.{{@last}}is only available when iterating over arrays, not objects. - To access a parent loop's index from inside a nested
#eachblock, use{{@../index}}. -
#eachdoes not render anything if the array or object is empty. Use the #isEmpty helper to handle the empty case explicitly.