$headerMenu=$repo->menu( 'header-nav' ); // will use the existing menu instance cached with this key$newMenu=$repo->menu( 'other-nav' ); // that key hasn't been used yet, so a new instance will be created and cached with that key

Filters

The menu can be filtered. Say you have a menu for usage in an admin area, or in a context with user auth levels or permissions. You have two options:

You can pass a filter closure to the getItems method that fill be used to filter the menu items.

// This will filter the items based on user permissions$menu->getItems(function($item) use ($user){return$user->can( $item->option( 'permissions', array() ) );});

You can add multiple filters to a menu with the addFilter($callable) method. These filters will be applied when the getItems method is called.

// This will add a filter that only lets the given user see the menu items if they have the appropriate auth level$menu->addFilter(function($item) use ($user){return$item->option('auth') <=$user->authLevel;});$menu->getItems();

You don't have to filter an entire menu - you can filter a submenu, too:

$about->addFilter(function(){return$item->isVisible();});

By default, any filters added with addFilter get applied to submenus.
You can override this behaviour by passing false as the second argument:

Manual Activation

You can manually activate any of those items with the setActive method:

$blog->setActive();

URL Matching

For a more automated approach, you can recursively mark one of those as activated based on the current URL. For example:

$menu->activate( $currentUrl );

This would match the given url against each of the menu's items, and mark them as active if the url matches. It also calls each item's children, and marks the parents as active if they have an active child item. ie. activeness bubbles up the chain.

So, if the current URL was http://foo.com/contact-us, this would mark the about menu item, and its child item, contact as active.

Advanced

If you want to match based on something different than URL, you can match against anything in a MenuItem's options array: