static class DirectiveNode.ForEachNode extends DirectiveNode
#foreach construct. While evaluating
#foreach ($x in $things), {$code $x} will be set to each element of $things in
turn. Once the loop completes, $x will go back to whatever value it had before, which
might be undefined. During loop execution, the variable $foreach is also defined.
Velocity defines a number of properties in this variable, but here we only support
$foreach.hasNext.| Modifier and Type | Class and Description |
|---|---|
private static class |
DirectiveNode.ForEachNode.ForEachVar
This class is the type of the variable
$foreach that is defined within
#foreach loops. |
DirectiveNode.ForEachNode, DirectiveNode.IfNode, DirectiveNode.MacroCallNode, DirectiveNode.SetNode| Modifier and Type | Field and Description |
|---|---|
private Node |
body |
private ExpressionNode |
collection |
private java.lang.String |
var |
lineNumber| Constructor and Description |
|---|
ForEachNode(int lineNumber,
java.lang.String var,
ExpressionNode in,
Node body) |
| Modifier and Type | Method and Description |
|---|---|
(package private) java.lang.Object |
evaluate(EvaluationContext context)
Returns the result of evaluating this node in the given context.
|
cons, emptyNode, evaluationException, evaluationExceptionprivate final java.lang.String var
private final ExpressionNode collection
private final Node body
ForEachNode(int lineNumber,
java.lang.String var,
ExpressionNode in,
Node body)
java.lang.Object evaluate(EvaluationContext context)
Node2 + 3 to 5 in order to set
$x to 5 in #set ($x = 2 + 3). Or it may be used directly as part of the
template output, for example evaluating replacing name by Fred in
My name is $name..