values by valdelimiter (default -), substitutes each non-empty value into text, and joins the results with outputdelimiter (default: nothing). Inside text the current value is _#1 — or its modern synonym _#loop (both are the value itself, not an index). Empty values are skipped.valdelimiter is the literal word json, values is read as JSON instead of being split by a character. A JSON array iterates into _#1; a JSON object names the variable after its key (a color key gives _#color); nested arrays produce the cartesian product with positional aliases _#loop0, _#loop1, …if/ifeq that depends on the current value must be wrapped in deferred-eval braces and reference the value as _##1 (double hash). Deferred-eval braces postpone evaluation until each iteration; without them the inner expression runs once, before the loop, so every row gets the same answer — e.g. you get NO|NO|NO instead of NO|YES|NO. See the two per-item condition examples below for the exact syntax.values requiredThe list of items foreach walks through. By default items are separated by a dash, so a-b-c is three items. Change the separator with the valdelimiter parameter (3rd), or set valdelimiter to json to pass a JSON array or object instead. Each item is exposed to the text template as _#1 (or its synonym _#loop). See the Examples below.
text requiredThe template expanded once for each item. Reference the current value with _#1 or its synonym _#loop. For JSON-object input each key becomes a named placeholder (_#color, etc.); for multilevel JSON arrays use positional _#loop0, _#loop1, and so on. For a per-item condition, wrap it in deferred-eval braces and use _##1 (see the per-item-condition example below).
valdelimiter optional default -The character (or string) separating items in the values parameter. Set it to a different character to split on that instead, or to the literal word json to parse values as a JSON array or object. See the Examples below.
outputdelimiter optional default (empty string)A string placed between each expansion of the text template, for example a comma-space for a list, a pipe with spaces, a space, or a newline. The delimiter goes only between items - there is no trailing separator after the last one. See the Examples below.
{foreach:a-b-c:item _#1 }
{foreach:Apple-Pear-Plum:[_#1]:-:}
{foreach:red|green|blue:_#1:|:, }
{foreach:one-two-three:_#loop:-:, }
{foreach:a--b-:_#1:-:|}
{foreach:["red","green","blue"]:_#1:json:, }
{foreach:{"color":["red","green"]}:_#color:json:, }
{foreach:[["A","B"],["1","2"]]:_#loop0=_#loop1:json:, }
{foreach:{sequence:num:2020:2022:1:-}:rok _#1:-:, }
{foreach:a-b-c:{({ifeq:_##1:b:YES:NO})}:-:|}
{foreach:en-cz-de:{({ifeq:_##1:en:English:cz:Czech:de:German:Unknown})}:-:, }
{foreach:{ids:SLICE_ID::publish_date:-}:{({item:_##1:_#HEADLINE})}:-:, }