I have a mega menu that displays child menu items when you click on a parent menu item in form of a drop-down menu. The thing is that, this menu, also displays cards as nodes and I want to add a theme suggestion only to this card nodes that are inside the menu drop-down.

I can get the node with a simple MYTHEME_theme_suggestions_node_alter() hook but I don't know how to get the menu item of it.

I've tried menu_ui_get_menu_link_defaults($node) as seen in this question but it always returns 'main', which is correct but, also almost every node on the page apart from the drop-down menu node seems to come from it and, therefore, that's not what I want.

All I need is an exclusive theme suggestion for this nodes represented on the mega menu drop-down

  • 3
    Why not just create a new view mode (e.g. menu_card), and render the nodes in that view mode? It'd be cleaner that way plus you get the standard node__menu_card suggestion already waiting for you
    – Clive
    Commented Nov 9, 2022 at 16:44
  • 2
    Yeah, display the nodes in that menu in a new view mode and you immediately have the template suggestion.
    – leymannx
    Commented Nov 9, 2022 at 17:46
  • Agree with the other commenters, new view mode is the way to go. Commented Nov 15, 2022 at 12:39

1 Answer 1


Adding a new view mode just for this types of nodes that are rendered on the menu, is the best approach, specially if this nodes are just from one bundle like 'page'.

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.