A small Twig question regarding array in array access. I have the following script, which is essentially listing categories, and then the subcategories associated to each category.
{% for category in categories %}
<li>
<a href="#">{{ category.name }}</a>
{% if category.subcategories|length > 0 %}
{% set subcategories = category.subcategories %}
<ul>
{% for subcategory in subcategories %}
<li>
<a href="#">{{ subcategory.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
The script above does not display subcategories and I have no clue as to why. The main problem is the fact that the for loop is never accessed. Dumping the subcategories variable right after setting it reveals the expected, that it holds the correct array, with one element.
Any ideas?
Dumping the subcategories variable reveals:
array (size=2)
0 =>
array (size=2)
'id' => int 1
'name' => string 'Dolls' (length=5)
1 =>
array (size=2)
'id' => int 2
'name' => string 'Test' (length=4)
{% for subcategory in category.subcategories %}?