|
ListsA 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
<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> </fm_code> <p> In FreeMarker Classic, if you gave a scalar as the list value, it would be treated as a list with a single element. This no longer works in FreeMarker 2, but there is a simple workaround. You can simply define a one-element list explicitly. </p> <fm_code><![CDATA[ <assign y=[x]> <foreach item in y> blah blah ${item} </foreach> Loop counterYou can access the loop counter (the number of times a list has iterated so
far) using the <foreach color in rainbow> ${color_index + 1}. ${color} </foreach> Note we add 1 to the index since it starts at zero, and we want our list to start at 1. "has-next" indicatorIn a similar fashion, you can use the Rainbow consists of <foreach color in rainbow> <if !color_has_next>and</if> ${color} <if color_has_next>, <else>.</if> </foreach> Breaking out of a loopAs of the second Lazarus release, you can use the <break> directive to break out of a loop. |
|