Skip to content

Instantly share code, notes, and snippets.

@ps-team
Last active December 15, 2022 08:28
Show Gist options
  • Save ps-team/38e2e447f02adb31c969 to your computer and use it in GitHub Desktop.
Save ps-team/38e2e447f02adb31c969 to your computer and use it in GitHub Desktop.
Recreating the Contensis Local View Menu in Razor
@using Contensis.Framework.Web
@using Contensis.Framework.Web.Search
<ul class="sys_menu">
@{
// Loading jQuery through the Contensis API
AppContext.Current.Page.Scripts.RegisterJQuery();
if(CurrentNode != null) {
var currentFolder = CurrentNode.Parent;
var currentDepth = CurrentNode.Parent.Depth;
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