In PHP I would do this:
$menu_groups = array();
foreach($items as $item){
$menu_id = $item['properties.menu_id'];
if(!array_key_exists($menu_id, $menu_groups)) $menu_groups[$menu_id] = array();
$menu_groups[$menu_id][] = $item;
}
How can I accomplish something similar in a Twig template?
2
Answers
as @pippo said in the comment templates should not contain the logic for better maitainability and testability and also for good practice of Symfony framework with twig as template engine. but if you insisted on knowing how you can do it I tried to transform your code from PHP to Twig and it should maybe look something like
if your group filter is not defined in your twig then maybe try to create one
then your new filter class should be like