I am trying to create an array and store the values ββin it inside a loop, but so far have failed. How can I do this using Twig?
I read them, but being new to Twig is hard to convert to my case.
- Twig for loop and array with key
- How to set array value in twig template
- building a twig-building array for a loop
- And much more
PLAIN PHP LOGIC THIS:
foreach ($array as &$value) { $new_array[] = $value; } foreach ($new_array as &$v) { echo $v; }
WHAT I GOT WITH TWIG:
{% for value in array %} {% set new_array = new_array|merge([value]) %} {% endfor %} {% for v in new_array %} {{ v }} {% endfor %}
symfony twig
Bentcoder
source share