-
Notifications
You must be signed in to change notification settings - Fork 0
Template Iteration
Templates allow you to create in-template iterations which allow you to enumerate collections, arrays, and lists.
The foreach tag is a regular orb-tag with a keyword preceding the @. But it has some special semantics.
Consider the following example:
@foreach{users}
- @{item.name} (Wage: @{item.salary})
@end{}
As a block token in MVEL templates, the block must be terminated with @end{}.
In the above example we iterate over a list of objects named users. By default, the element from the collection on each iteration is named item. However, you may use the as keyword to re-assign it to something else to deal with nesting:
@forach{users as user}
Name: @{user.name}
Roles:
@foreach{user.roles as role}
- @{role.name}
@end{}
@end{}
MVEL also allows you to iterate over multiple collections, as long as they are each the same size. This can be particularly useful when generating method signatures.
sometMethod(@foreach{types, identifiers as type, identifier}type identifier@end{","})
The string supplied, @end{","}, at the end is optional and is the delimiter used between each iteration.
This is the documentation for MVEL 1.2.x and 1.3.x. If you are using MVEL 2.*, please proceed to the documentation for MVEL 2.*