A list structure looks like this:
<list listExpression as indexVariable> Some HTML... </list>
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>
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 |