P
P
Pavel Inky2017-07-05 20:07:34
HTML
Pavel Inky, 2017-07-05 20:07:34

How to make one array from another in Twig?

Hi all.
I have an array cat_arr and I want to populate it with the name and url fields from categories_ss. How to do it right?
Here are my samples. But in the end, in the cat_arr array, I only have the last element. In theory, merge should not work like this.

{% set cat_arr = {} %}
   {% for category in categories_ss %}
   {% set caturl = cat_map_hr(category) %}
   {% set cat_arr = cat_arr | merge( {name: category.name, url : caturl } ) %}
{% endfor %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Inky, 2017-07-05
@inkyrein

Made it myself
merge( [{name: category.name, url : caturl }] )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question