Variables (referred to as $name
) can be defined in
range
and with
actions. For range
, the syntax is:
{{range $index, $element = pipeline }} T1 {{end}}
where index and element are arbitrary variable names. When executing this action, during each iteration $index and $element are set to the index (attribute name) and value of each successive element. Dot remains unaffected.
For with
, the syntax is:
{{with $var = pipeline }} T1 {{end}}
Pipeline is evaluated, its result is assigned to $var and the T1 block is executed with dot unchanged.
A variable’s scope extends to the end
action of the control
structure (with
or range
) in which it is declared. This
includes any nested statements that may appear in between.