Chapter 5 Customizing Generation with GTL
This macro is used for iterating on object collections:
.foreach_item (collection [,head [,tail [,condition [,comparison]]]]) complex-template .next [(separator)]
The template specified inside the block is applied to all objects contained in the specified collection.
If a comparison is specified, items in the collection are pre-sorted according to the corresponding rule before being iterated upon.
The following parameters are available:
Parameter | Description |
---|---|
collection | Collection over which iteration is performed
Type: Simple template |
head | [optional] Generated before output, if there is one
Type: Text |
tail | [optional] Appended to the output, if there is one
Type: Text |
condition | [optional] If specified, only objects satisfying the given condition are considered during the iteration
Type: Simple condition |
comparison | [optional] evaluated in a scope where two local objects respectively named 'Item1' and 'Item2' are defined. These correspond to items in the collection. <comparison> should evaluate to true if Item1 is to be placed after Item2 in the iteration
Type: Simple condition |
complex-template | Template to apply to each item.
Type: Complex template |
separator | [optional] Generated between non empty evaluations of <complex-template>
Type: Text |
Macro parameters delimiters
Macro parameters may be delimited by double quotes. The delimiters are required whenever the parameter value includes commas, braces, leading or trailing blanks. The escape sequence for double quotes inside a parameter value is \"
.
Example:
Attribute | Data type | Initial value |
---|---|---|
cust_name | String | __ |
cust_foreign | Boolean | false |
.foreach_item(Attributes,,,,%Item1.Code% >= %Item2.Code%)) Attribute %Code%[ = %InitialValue%]; .next(\n)
The result is:
Attribute cust_foreign = false
Attribute cust_name;
The four commas after (Attributes,,,, means that all parameters (head, tail, condition and comparison) are skipped.
Copyright (C) 2008. Sybase Inc. All rights reserved. |
![]() |