Last Updated: April 14, 2016
·
869
· say_ten

"Active" navigation in Umbraco

Here's the scenario, you're building navigation in Umbraco and you want to flag the three with active classes. So you need to know if the current navigation item is part of the current page's path in the tree. Simple check the current page ID against the navigation items path property, something like:

var currentPageId = UmbracoContext.Current.PageId.ToString();
var pathIds = navigationItem.Path.Split(',').ToList<string>();
var active = pathIds.Contains(currentPageId)