Format:
#foreach( $ref1 in $ref2 ) [ statement... ]
#end
Usage:
-
$ref1 - The first variable reference is the
item.
-
$ref2 - The second variable reference is the list
that holds the items.
-
statement - What is output each time Velocity finds a
valid item ($ref1) in the list ($ref2).
Velocity provides an easy way to get the loop counter so that you
can do something like the following:
<table>
#foreach( $customer in $customerList )
<tr><td>$velocityCount</td><td>$customer.Name</td></tr>
#end
</table>
The default name for the loop counter variable reference, which
is specified in the velocity.properties file, is $velocityCount. By default the counter starts at 1, but this can be set to
either 0 or 1 in the velocity.properties file. Here's what the
loop counter properties section of the velocity.properties file
appears:
# Default name of the loop counter
# variable refernce. counter.name = velocityCount
# Default starting value of the loop
# counter variable reference. counter.initial.value = 1
|