Trying to output the index # of an array in twig, having trouble finding it in the docs. Anyone know how to get it?
array(2) {
[0]=>
array(2) {
["testimonial"]=>
string(18) "Derby Heist Test 1"
["author"]=>
string(6) "test 1"
}
[1]=>
array(2) {
["testimonial"]=>
string(18) "Derby Heist Test 2"
["author"]=>
string(6) "test 2"
}
}
so I'd like to output the index numbers 0 and 1 in a for loop. Please help.
You can use The loop variable as example:
{% for user in users %}
{{ loop.index }} - {{ user.username }}
{% endfor %}
loop.index The current iteration of the loop. (1 indexed)
loop.index0 The current iteration of the loop. (0 indexed)
Hope this help
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