Template Engine language reference > Script variable interface > Looping over arrays

Looping over arrays
To be able to include several array values in the output, you must use the #foreach directive to loop over arrays (see The #foreach directive).
Looping over all values in a one dimensional array
If you do not know in advance how many values there are in an array, you can create a #foreach directive that loops over all values in a one dimensional array.
Example 15
In this example, the #foreach directive loops over all values of the array $array, and writes the values to the output. The variable $array is defined in a StreamServe script.
#foreach($j in $variables.array)
$j
#end
 
Looping over an array using a fixed range
You can also create a #foreach directive that loops over a fixed number of values of an array.
Example 16
In this example, the #foreach directive loops over the first four values of the array $array, and writes the values to the output.
#foreach($j in [0..3])
$variables.array[$j]
#end
 
Looping over an array using a variable range
In the StreamServe script you can create a counter variable that defines the full range of an array, and then use this counter variable to define the range to loop over.
Example 17
In this example, the #foreach directive loops over the range [0..$counter] of the array $array, and writes the values to the output. The variables $array and $counter are defined in a StreamServe script.
#foreach($j in [0..$variables.counter])
$variables.array[$j]
#end
 
OpenText StreamServe 5.6 Updated: 2013-03-01