Issue
Is it possible to get the key of an array in Twig (in Symfony)?
For example if I have an array of:
array(
'key1' => 'value1',
'key2' => 'value2',
);
Is it possible in Twig to print:
key1: value1
key2: value2
Thanks
Solution
Try following format:
{% for key, value in array %}
{{ key }} - {{ value }}
{% endfor %}
More Information on Offical Twig about Iterating over Keys and Values
https://twig.symfony.com/doc/3.x/tags/for.html#iterating-over-keys-and-values
Answered By - Bora
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.