This macro iterates over a collection of sub-objects or related objects.
.foreach_item (collection [,head [,tail [,filter [,order]]]]) output .next [(separator)]
The following parameters are available:
Parameter |
Description |
---|---|
collection |
Specifies the collection over which to iterate. Type: Simple template |
head |
[optional] Specifies text to be generated before the output, unless the collection is empty. Type: Text |
tail |
[optional] Specifies text to be generated after the output, unless the collection is empty. Type: Text |
filter |
[optional] Specifies a filter to apply to the collection before iteration. Type: Simple condition |
order |
[optional] Specifies the order in which the
collection will be iterated in the
format:
%Item1.property% <= %Item2.property%When the comparison evaluates to true, %Item1% will be placed after %Item2%. By default, the collection is ordered alphabetically by name. Type: Simple condition |
output |
Specifies the text to output for each item in the collection. Type: Complex template |
separator |
[optional] Specifies text to be generated between each instance of output. Type: Text |
Examples |
---|
Simple
list:.foreach_item(Attributes) *%Code% (%DataType%)[ = %InitialValue%]; .next(\n)Result: *available (boolean) = true; *actualCost (int); *baseCost (int); *color (String); *height (int) = 10; *width (int) = 5; *name (int); |
With head and
tail:.foreach_item(Attributes,Attributes:\n,\n\nEnd of Attribute List) *%Code% (%DataType%)[ = %InitialValue%]; .next(\n)Result: Attributes: *available (boolean) = true; *actualCost (int); *baseCost (int); *color (String); *height (int) = 10; *width (int) = 5; *name (int); End of Attribute List |
With
filter:.foreach_item(Attributes,,,%.1:Code%==a) *%Code% (%DataType%)[ = %InitialValue%]; .next(\n)Result: *available (boolean) = true; *actualCost (int); |
With reverse alphabetical
ordering:.foreach_item(Attributes,,,, %Item1.Code% <= %Item2.Code% ) *%Code% (%DataType%)[ = %InitialValue%]; .next(\n)Result: *width (int) = 5; *name (int); *height (int) = 10; *color (String); *baseCost (int); *available (boolean) = true; *actualCost (int); |