Map

A map flow allows a block of code to be executed once for each item in a dictionary. Note that the order of iteration is not guaranteed given the nature of dictionaries. Loops can also contain more nested loops inside them.

In order to iterate over just values or key, use appropriate transformers .keys() and .values() on the source dictionary.

If you want to iterate over an array, use for flow instead.

Syntax

Basic syntax of map flow is as follows:

{[ map [statement] into [key] [value] ]}
    Body, optionally using {{ key }} and {{ value }}
{[/]}

With the following required attributes:

  • key - the newly created property where the iterated key is stored

  • value - the newly created property where iterated value is stored

  • statement - statement to be evaluated to retrieve data for the iterator. Dictionary is expected otherwise an error is thrown

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

{
    "attributes": {
        "Stamina": "10",
        "Agility": "20",
        "Intelligence": "9001"
    }
}

You can iterate on user data by defining new variables attributeName and attributeValue where each key and value of the dictionary get stored in each iteration:

<h1>Player stats</h1>
<ul>
    {[ map attributes to attributeName attributeValue ]}
    <li>{{ attributeName }}: ({{ attributeValue }})</li>
    {[/]}
</ul>

With each iteration, data in both attributeName and attributeValue is different, resulting in the following output:

<h1>Player stats</h1>
<ul>
    <li>Stamina: 10</li>
    <li>Agility: 20</li>
    <li>Intelligence: 9001</li>
</ul>

Last updated