Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question