DrupalX

Extension
Framework

root

Chainable

Chainable

You can use the "root" method to set any arbitrary menu item as the new root node. Basically, this just means that you create a sub-tree or partial menu. This method gets an object of type MenuItem as an argument which can obivously be determined in various ways (e.g. using the current or trail property etc.). The following example set the current main menu item as a new root node. This will render a sub-menu which always matches the currently active main menu item:

<nav role="navigation menu">
  <h1>Category menu</h1>
  {% set mymenu=Menu::load("main") %}
  {{ mymenu.root(mymenu.trail[0]) }}
</nav>