How can I set member of an already existing array from Twig?
I tried doing it next way:
{% set arr[\'element\'] = \'value\' %}
but
I have tried @LivaX 's answer but it does not work , merging an array where keys are numeric wont work ( https://github.com/twigphp/Twig/issues/789 ).
That will work only when keys are strings
What I did is recreate another table ( temp
) from the initial table (t
) and make the keys a string , for example :
{% for key , value in t%}
{% set temp= temp|merge({(key~'_'):value}) %}
{% endfor %}
t
keys : 0 , 1 , 2 ..
temp
keys : 0_, 1_ , 2_ ....