The for
Dynamic Shortcode can be used to loop through an iterable value (for example an array) and print a template for each iteration.
It takes three arguments.
A name to be given as a placeholder for the current value in the loop. This can later be retrieved with the
get
Shortcode.The iterable value to loop over.
Another value to be printed at each iteration. Usually a template with Shortcodes, but can also be a single a Shortcode.
Example:
<ul>
{for:item {array:dog cat llama} [<li>{get:item}]}
</ul>
will print
dog
cat
llama
Associative Arrays
Too loop through an associative array you have to pass two identifiers before the array. For example:
{for:key value <array> [do something with {get:key} and {get:value}]}
Separator
You can add a separator with the sep
keyarg.
Example:
{for:item {array:dog cat llama} {get:item} @ sep=', '}
Will print
โdog, cat, llama