Umbraco Razor 2nd Level Navigation - Check to see whether the Current Page is a Child of the Page being written out


Umbraco Razor 2nd Level Navigation - Check to see whether the Current Page is a Child of the Page being written out, if so syle it:



@inherits umbraco.MacroEngines.DynamicNodeContext
@{
  var startLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.StartLevel);
  var finishLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.FinishLevel);  
  var parent = @Model.AncestorOrSelf(startLevel);
  if (parent != null) { @traverse(parent,startLevel,finishLevel) ; }
}                                                    
             





@helper traverse(dynamic parent,int startLevel,int finishLevel)
{
int test = parent.Children.Count();



if (test > 0)
{
@Html.Raw("<div class=\"wrapper row9\">");
@Html.Raw("<div id=\"container1\">");
  @Html.Raw("<div id=\"navcontainer\">");
@Html.Raw("<ul id=\"navlist\">");

}


foreach (var node in parent.Children.Where("Visible"))
{
 var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"selected\"" : "";






if(@node.Url == @Model.Url)
{
<li>
@if (@node.secondLevelNavName != "" && @node.secondLevelNavName != null)
{
<a href="@node.Url"><span style="text-decoration:underline">@node.secondLevelNavName</span></a>
}
else
{
<a href="@node.Url"><span style="text-decoration:underline">@node.navigationName</span></a>                                
}
</li>
}
else
{


//  ** Check to see if the curent page is a child of the page being listed
if(@node.Id == @Model.Parent.Id)
{
@Html.Raw("<li style=\"text-decoration:underline\">");
}
else
{
@Html.Raw("<li>");
}



if (@node.secondLevelNavName != "" && @node.secondLevelNavName != null)
{

if(@node.Id == @Model.Parent.Id)
{
@Html.Raw("<span style=\"text-decoration:underline\">");
}
<a href="@node.Url">@node.secondLevelNavName</a>
}
else {
<a href="@node.Url">@node.navigationName</a>
}

@Html.Raw("</li>");
}





}


if (test > 0)
{
@Html.Raw("</ul>");
@Html.Raw("</div>");
@Html.Raw("</div>");
@Html.Raw("</div>");
}
                                                 
}

Comments

Popular posts from this blog

Umbraco - Reset the Admin Password via SQL Server

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version