1

For a mega menu, I'm trying to add theme suggestions to every parent menu item / menu link depending on the chosen view mode for that menu item.

I'm aware of the MYTHEME_theme_suggestions_menu_link_content_alter() function but it does not work for me.

Every menu item has a view mode field but since I can't use a hook to preprocess it, I cannot create any theme suggestion for menu items .When I try to use the theme_suggestion hook on the menu, I can only see items like this: menu items inside from menu hook

Am I missing something? Is it possible to add theme suggestions to menu items? If so,how can I do that?

1 Answer 1

1

View modes in menu items don't come from core. You are probably using the Menu Item Extras module.

You can look at the Menu Item Extras module's code which does what you are asking for in menu_item_extras.module#L158-184.

But to have the suggestions kick in, you maybe need to make your current menu--MY-MENU.html.twig print actual menu item {{ content }} first.

Alternatively for testing try to remove any prior menu--MY-MENU.html.twig to have the menu--extras.html.twig kick in and see how the suggestions by view mode appear. You even get one suggestion for the level.

<!-- FILE NAME SUGGESTIONS:
   * menu-link-content--main--1--MY-VIEW-MODE.html.twig
   * menu-link-content--main--1.html.twig
   * menu-link-content--main--menu-level-0--MY-VIEW-MODE.html.twig
   * menu-link-content--main--menu-level-0.html.twig
   * menu-link-content--menu-level-0.html.twig
   * menu-link-content--main--MY-VIEW-MODE.html.twig
   * menu-link-content--main.html.twig
   * menu-link-content--MY-VIEW-MODE.html.twig
   x menu-link-content.html.twig
-->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.