Template code Chunk output
{#example_1}
{!-- Lists are zero-indexed, so the first element
  -- is get(0) and the third element is get(2)
  --}
<div>The beatles are: {% $beatles|join(, ) %}.</div>
<div>The third beatle is {% $beatles|get(2) %}.</div>
{#}
Theme theme = new Theme("examples");
 
// fetch template snippet from themes/examples/arrayindex.chtml
Chunk html = theme.makeChunk("arrayindex#example_1");

html.set("beatles", new String[]{"John","Paul","George","Ringo"} );

StreamWriter out = getStreamWriter();
html.render(out);
<div>The beatles are: John, Paul, George, Ringo.</div>
<div>The third beatle is George.</div>

The beatles are: John, Paul, George, Ringo.
The third beatle is George.
Template code Chunk output
{#example_2}
<pre>
{$beatles|get(0)}
{$beatles|get(1)}
{$beatles|get(2)}
{$beatles|get(3)}
{$beatles|get(4)}
</pre>

<pre>
{$beatles|get(-1)}
{$beatles|get(-2)}
{$beatles|get(-3)}
{$beatles|get(-4)}
{$beatles|get(-5)}
</pre>
{#}
Theme theme = new Theme("examples");
 
// fetch template snippet from themes/examples/arrayindex.chtml
Chunk html = theme.makeChunk("arrayindex#example_2");

html.set("beatles", new String[]{"John","Paul","George","Ringo"} );

StreamWriter out = getStreamWriter();
html.render(out);
<pre>
John
Paul
George
Ringo

</pre>

<pre>
Ringo
George
Paul
John

</pre>

John
Paul
George
Ringo

Ringo
George
Paul
John