FOREACH Reference
The FOREACH loop allows you to iterate through items in a list.
Implicit variables
- ###LOOP_SIZE### —> number of elements in the list
- ###LOOP_INDEX### —> index of current iteration from 0 to size - 1
- ###LOOP_MAX### —> Returns the maximum index number (i.e. the index of the last element)
- ###LOOP_FIRST### —> true if the current iteration is the first
- ###LOOP_LAST### —> true if the current iteration is the last
- ###LOOP_COUNT### —> Returns the current iteration count in the range of 1 to size.
- ###LOOP_ODD### —> Returns a boolean (0/1) value to indicate if the current iterator count (starting at 1) is an odd number.
- ###LOOP_EVEN### —> Returns a boolean (0/1) value to indicate if the current iterator count (starting at 1) is an even number.
- ###LOOP_MOD(<number>)### —> Returns the remainder of index (LOOP_INDEX) divided by number (aka modulo).
Example 1
The below example concatenates all the product codes together separating them with commas.
[FOREACH="BASKET"] [IF="LOOP_INDEX"!="0"],[ENDIF="LOOP_INDEX"]###BRPRODCODE### [ENDFOREACH="BASKET"]
Example 2
The below example lists all the store front product names in a 3 column table.
[FOREACH="STOREFRONT_PRODUCTS"] [IF="LOOP_MOD(3)"=="0"]<tr>[ENDIF="LOOP_MOD(3)"]###PRODUCT_NAME### [IF="LOOP_MOD(3)"=="2"]</tr>[ENDIF="LOOP_MOD(3)"] [IF="LOOP_LAST"] [IF="LOOP_MOD(3)"=="0"]<td> </td><td> </td></tr>[ENDIF="LOOP_MOD(3)"] [IF="LOOP_MOD(3)"=="1"]<td> </td></tr>[ENDIF="LOOP_MOD(3)"] [ENDIF="LOOP_LAST"] [ENDFOREACH="STOREFRONT_PRODUCTS"]
