Search code examples
drupalmenuhierarchical

Drupal hierarchical menu


I'm new to Drupal, and I'm also building an N-tier hierarchical menu that I want to display sections at time based on the current $node->path.

The menu looks like this -

---Top
------Menu-1
---------Menu-2
------------Menu-3
------Menu-4
---------Menu-5
------------Menu-6
etc etc etc

Each menu is also a page content type in Drupal, so if the $node-path is /top/menu-3, I want to be able to grab only Menu-1 and all its children. As I'm saying this, it almost sounds like I need some xpath in here.


Solution

  • With the Menu Block module, you can create a block to display a menu just like the Drupal's menu built-in menu block but starting at a specific depth. In your example, you can create a block to display your menu starting at depth 2 (Menu 1 and Menu 4) and following the active item (ie. the menu item for the currently viewed page). When viewing Menu 1, Menu 2 or Menu 3, the block will display Menu 1 and its children. When viewing Menu 4, Menu 5 or Menu 6, the block will display Menu 4 and its children. And when viewing Top, the menu will be empty.

    Also, it works with non-node pages.