For

A for flow allows a block of code to be executed once for each item in an array. You can change the order of iteration by using array transformers such as .sorted() or .reversed() on the source data. Additionally, nested loops are fully supported.

If you want to iterate over dictionary, use map flow instead.

Syntax

Basic syntax of for flow is as follows:

{[ for [property-name] in [statement] ]}
    Body, optionally using {{ value }}
{[/]}

With the following required attributes:

  • property-name - the newly created property where iterated data is stored

  • statement - statement to be evaluated to retrieve data for the iterator. Array is expected

For example, a for flow be used to create lists, menus, and similar structures from sourced data. Let's assume we have a variable users defined that contains following data:

[{
    "name": "Jiri",
    "type": "member"
}, {
    "name": "Artem",
    "type": "admin"
},{
    "name": "Ydus",
    "type": "member" 
},{
    "name": "Oskar",
    "type": "visitor"
}

You can iterate on user data by defining a new variable user where each item in the array gets stored in each iteration:

<h1>Team Members</h1>
<ul>
    {[ for user in users ]}
    <li>{{ user.name.capitalized() }} ({{ user.type }})</li>
    {[/]}
</ul>

With each iteration, data in user is different, resulting in the following output:

<h1>Team Members</h1>
<ul>
    <li>JIRI (Member)</li>
    <li>ARTEM (Admin)</li>
    <li>YDUS (Member)</li>
    <li>OSKAR (Visitor)</li>
</ul>

Last updated