Hi Guys
I'm trying to make my first Razor navigation.
My problem right now is I really don't know how to add an class to my active node.
Can anyone help me with this - and maybe try to make me understand?
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage@{
if (Model.Content.AncestorOrSelf(1).Children.Count() > 0) { <ul id="navigationBar" class="nav navbar-nav"> @foreach (var mainNodes in Model.Content.AncestorOrSelf(1).Children.Where("TemplateId != 0 && Visible")) { if (mainNodes.Children.Where("TemplateId != 0 && Visible").Count() > 0) { <li class="@(mainNodes.IsAncestorOrSelf(CurrentPage) ? "active" : null)"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">@mainNodes.Name<b class="caret"></b></a> <ul class="dropdown-menu"> @foreach(var subNodes in mainNodes.Children.Where("TemplateId !=0 && Visible")) { <li><a href="@subNodes.Url">@subNodes.Name</a></li> } </ul> </li> }else{ <li> <a href="@mainNodes.Url">@mainNodes.Name</a> @if(CurrentPage.AncestorOrSelf.Id == mainNodes.Id ){ <span>juhu</span> } </li> } } </ul> }}
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/48200-if-currentpage-add-active-class