You are viewing beta documentation for Navigation 4.x.
Reference

Context

A NavigationContext describes the current page’s position in a menu. Obtain it in Twig with craft.navigation.context('mainMenu'), or pass node criteria as a second argument: craft.navigation.context('mainMenu', { siteId: currentSite.id }).

The current node is the deepest exact URL match and can be a stored Node or a ProjectedNode. See Build a Section Sidebar for a complete use case.

Methods

current()

Returns: Deepest exact-match node

Deepest exact-match node

currentNodes()

Returns: All exact matches, deepest first

All exact matches, deepest first

activeNodes()

Returns: All branch-active nodes

All branch-active nodes

parent()

Returns: Parent of deepest current node

Parent of deepest current node

ancestors()

Returns: Root → parent of current

Root → parent of current

siblings()

Returns: Same-level nodes under shared parent

Same-level nodes under shared parent

children()

Returns: Direct children of deepest current node

Direct children of deepest current node

branch()

Returns: Ancestors + current + siblings (common sidebar set)

Ancestors + current + siblings (common sidebar set)

When no node exactly matches the request URL, current() and parent() return null; methods based on that current node return empty arrays. activeNodes() can still contain path-active nodes. Supplying criteria does not replace the request URL used for matching.