The for loop iterates a range of integer values. Within the code block of the loop, the current value is represented by the :i runtime variable.
<@ for 1 to 5 @>
<p>@{ :i }</p>
<@ end @>
Instead of numbers, it is also possible to use variables in order to define the range:
<@ for @{ start } to @{ end } @>
<p>@{ :i }</p>
<@ end @>
Example
A typical use case for a for loop is a pagination navigation for a pagelist. The :paginationCount variable defines the end of the range and the queryStringMerge function is used to build links that keep all other query string parameters.
<@ newPagelist {
type: 'children',
limit: 10,
page: @{ ?page | def (1) }
} @>
<@ for 1 to @{ :paginationCount } @>
<a
href="?<@ queryStringMerge { page: @{ :i } } @>"
<@ if @{ :i } = @{ ?page | def (1) } @>class="active"<@ end @>
>
@{ :i }
</a>
<@ end @>