Loop
loop, foreach
Description
{{ loop $foo = $bar to $baz }}
{{ end }}
{{ loop }}
run looping until {{ end }}
by assigned variables. It is same to for( $foo=$bar; $bar<=$baz; $foo++ )
.
{{ foreach $array as $key => $val }}
{{ end foreach }}
{{ foreach }}
run looping until {{ end foreach }}
by assigned array variable. You can get loop count from $foreachIndex
in {{ foreach }}
.
Example
loop
Template
// $bar = 1, $baz = 5
<ul>
{{ loop $foo = $bar to $baz }}
<li>{{ $foo }}</li>
{{ end }}
</ul>
Output
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
foreach
Template
// $array = array( 'foo' => 'bar', 'baz' => 'qux' );
<ul>
{{ foreach $array as $key => $val }}
<li>{{ $foreachIndex }} : {{ $key }} => {{ $val }}</li>
{{ end foreach }}
</ul>
Output
<ul>
<li>0 : foo => bar</li>
<li>1 : bar => qux</li>
</ul>