Template Engine language reference > Message interface > Looping over blocks

Looping over blocks
To be able to include fields defined in blocks (recurring fields) in the output, you must use the #foreach directive to loop over the blocks (see The #foreach directive).
Looping over all instances of a block
Since you cannot know in advance how many instances of a block there is in a Message, you can create a #foreach directive that loops over all instances of a block in the Message.
Example 12
In this example, the #foreach directive loops over all instances of the block blkA, and writes the value of the field Description to the output.
#foreach($j in $message.blkA)
$j.Description
#end
 
Looping over a fixed number of instances of a block
You can also create a #foreach directive that loops over a fixed number of instances of a block in the Message.
Example 13
In this example, the #foreach directive loops over the first four instances of the block blkA, and writes the value of the field Description to the output.
#foreach($j in [0..3])
$message.blkA[$j].Description
#end
 
Using * to loop over blocks
You can use a wildcard (*) to loop over all blocks in a Message, or over all sub-blocks in a block.
Example 14
In this example, the #foreach directive loops over all instances of all blocks in the Message, and writes the value of the field description in block blkA and the value of the field type in block blkB to the output.
#foreach($j in $message.*)
#if($j.name()=='blkA')
$j.description
#end
#if($j.name()=='blkB')
$j.type
#end
#end
 
OpenText StreamServe 5.6 Updated: 2013-03-01