A list structure looks like this:
<list listExpression as indexVariable> Some HTML... </list>
Or like this:
<foreach indexVariable in listExpression> Some HTML... </foreach>
The structure iterates through the items in the list referred to by
listExpression
. Within the loop body,
indexVariable
is used to refer to each element of the
list in turn. (The index variable acts as a local
variable; any value it has outside the loop is hidden within the loop
body.) The list structure is particularly useful for building HTML
tables using dynamic data. For example:
<table border="1"> <tr> <td>Date</td> <td>Amount</td> </tr> <list deposits as deposit> <tr> <td>${deposit.date}</td> <td>${deposit.amount}</td> </tr> </list> </table>
Since lists can be nested, you can make tables that have a variable number of rows and columns. For example:
<table border="1"> <list rows as cells> <tr> <list cells as cell> <td>${cell}</td> </list> </tr> </list> </table>
You can also iterate over list literals. For instance:
<foreach item in [ 1 .. 10 ]> Item ${item} is: ${items[ item ]}.<br> </foreach>
A list instruction can be terminated with an optional
<break>
instruction. For instance:
<foreach item in [ 1 .. itemCount ]> Item ${item} is: ${items[ item ]}.<br> <if items[ item ] == favouriteItem> <break> </if> </foreach>
If the list variable is a scalar, the list structure will treat it as a list value having one element.
Previous: Expressions | Next: If-Else |