Score:1

Provide theme suggestions for menu content items

fj flag

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?

Score:1
ne flag

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
-->
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.