Skip to content
Advertisement

Reorganize array in twig

I want to invert my array so that the categories are first so that I can better manage my foreach later. I managed to achieve it, but merge has removed the same keys. And I should not add value as another item in the array.

Default Array:

JavaScript

After Merge: ( two records have been deleted :()

JavaScript

What is he trying to achieve?

JavaScript

Code:

JavaScript

Advertisement

Answer

First a FYI though, this is not something you should be doing in the template, cause the code is pretty messy. Anyway here is how you merge/group arrays in twig:

JavaScript

demo

related problem

issues with merge in twig

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement