@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
@{
FolderNode topFolder = null;
//Always get the current top folder regardless of depth of the current page
if(CurrentNode.Parent.Depth > 1) {
topFolder = CurrentNode.Parent.AncestorAtDepth(1);
}else{
topFolder = CurrentNode.Parent;
}
//Get all nodes that have been marked as a top menu page
var query = Query.Where("MD_TopMenuPage").IsEqualTo("true");
var pages = new NodeFinder().Find(query);
//Need to initialise counter to assign class/id to each top menu link
var linkClass = "";
var i =1;
}
<ul id="nav">
@foreach (var page in pages.OrderBy(p => p.Parent.MenuOrder)){
//Get the folder node for the current page in the loop
FolderNode pageTopFolder = null;
if(page.Parent.Depth > 1) {
pageTopFolder = page.Parent.AncestorAtDepth(1);
}else{
pageTopFolder = page.Parent;
}
//Add unqiue class
//Add selected class if page top folder and CurrentNode top folder matach
if(pageTopFolder.ID == topFolder.ID) {
linkClass = "sys_nav-item" + @i + " sys_selected";
}else{
linkClass = "sys_nav-item" + @i;
}
<li>
<a href="@page.Path" class="@linkClass" title="@page.Title">@page.MenuName</a>
@{
//Check for sub level pages and display if they exist
string pagePath = page.Data.Property_Path.ToString();
var subPagesQuery = Query.Where("Property_Path").Contains(pagePath);
var subPages = new NodeFinder().Find(subPagesQuery);
}
@if (subPages.Count > 0) {
<ul>
@foreach (var subPage in subPages.Where(sp => sp.Depth == page.Depth + 1)){
//Loop through sub pages and only shows page one level below
//Add selected class if subPage Node and CurrentNode matach
if(CurrentNode.ID == subPage.ID) {
<li>
<a class="sys_selected" href="@subPage.Path" title="@subPage.Title">@subPage.MenuName</a>
</li>
}else{
<li>
<a href="@subPage.Path" title="@subPage.Title">@subPage.MenuName</a>
</li>
}
}
</ul>
}
</li>
i++;
}
</ul>