I would like to access element of array directly using template toolkit.
e.g. we can easily do this,
[% FOREACH item IN array %]
[% item %]
[% END %]
Can I access directly 0th , 1st, 2nd etc. elements without using any loop?
e.g.
`[% array[0] %]`
You can do it like this:
[% array.0 %]
If the index is inside a variable:
[% array.$index %]
The documentation can be found at www.template-toolkit.org/docs/manual/Variables.html#section_List_References.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With