Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 10:06
Show Gist options
  • Save ps-team/5bd90ab67d1d35a30b5a4416985eeece to your computer and use it in GitHub Desktop.
Save ps-team/5bd90ab67d1d35a30b5a4416985eeece to your computer and use it in GitHub Desktop.
A razor view that mimics the functionality of our local view menu control buts outputs semantic markup and classes that allow for easier and more flexible styling
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<ul class="sys_menu">
@{
AppContext.Current.Page.Scripts.RegisterJQuery();
if(CurrentNode != null) {
//This will be replaced by a function in future releases
var currentFolder = CurrentNode.Parent;
var currentDepth = CurrentNode.Parent.Depth;
var test = CurrentNode.Data.MD_Description;
for(int i=1; i<currentDepth; i++){
var currentAncestor = CurrentNode.Parent.AncestorAtDepth(i);
foreach (var aPage in currentAncestor.Children<ContentNode>().Where(aP => aP.IsHomePage == true && aP.IncludeInMenu == true && aP.IsWebPage == true ).OrderBy(aP => aP.MenuOrder)){
<li><a href="@aPage.Path" title="@aPage.Title">@aPage.Parent.MenuName</a></li>
}
}
foreach (var page in currentFolder.Children<ContentNode>().Where(p => p.IsHomePage == true && p.IncludeInMenu == true && p.IsWebPage == true && p.Depth <= CurrentNode.Depth)){
if(CurrentNode.Depth == page.Depth) {
<li class="sys_current-folder"><a href="@page.Path" title="@page.Title">@page.Parent.MenuName</a>
<ul class="sys_sub-menu">
@foreach (var subPage in CurrentNode.Parent.Children<ContentNode>().Where(sP => sP.IsHomePage == false && sP.IncludeInMenu == true && sP.IsWebPage == true).OrderBy(sP => sP.MenuOrder)) {
//If the currnet node matches the current node in the loop add current page class
//Otherwise, output link as normal
if(subPage.ID == CurrentNode.ID) {
<li class="sys_selected"><a 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>
}
}
}else {
<h1>CurrentNode is Null</h1>
}
}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment