Skip to content

Instantly share code, notes, and snippets.

@ps-team
Created October 27, 2017 10:02
Show Gist options
  • Save ps-team/68d56a048bf80ae991d630233bb77cb4 to your computer and use it in GitHub Desktop.
Save ps-team/68d56a048bf80ae991d630233bb77cb4 to your computer and use it in GitHub Desktop.
A top menu razor that is set using a folder of hyperlink content types. Allows restricted editing by certain user groups. Also has data attribute for target node ID for use with an ajax mega menu.
@using Contensis.Framework.Web;
@using Contensis.Framework.Web.Search
<ul id="menu" class="sys_navbar">
<li class="sys_topnav"><a class="sys_home" href="/" title="Home"><img src="/SiteElements/img/homeicon.png" width="23" height="48" alt="Home" /></a></li>
@{
var query = Query.Where("Property_F_ID").IsEqualTo("48"); // Add ID of folder to target here
var pages = new NodeFinder().Find(query);
var linkClass = "";
FolderNode topFolder = null;
if(CurrentNode.Parent.Depth > 1) {
topFolder = CurrentNode.Parent.AncestorAtDepth(1);
}else{
topFolder = CurrentNode.Parent;
}
foreach(var node in pages.Where(np => np.IncludeInMenu && np.Path.Length > 1).OrderBy(p => p.MenuOrder))
{
ContentNode MenuItemNode = null;
MenuItemNode = (ContentNode)new NodeFactory().Load(@node.Path);
//Get the folder node for the current page in the loop
FolderNode pageTopFolder = null;
if(MenuItemNode.Parent.Depth > 1) {
pageTopFolder = MenuItemNode.Parent.AncestorAtDepth(1);
}else{
pageTopFolder = MenuItemNode.Parent;
}
if(pageTopFolder.ID == topFolder.ID) {
linkClass = "sys_nav-item" + " sys_selected";
}else{
linkClass = "sys_nav-item";
}
if(node is ContentNode)
{
ContentNode content = (ContentNode)node;
if(node.Data.MD_NoDropdown == false && node.Data.MD_Portals == false)
{
<li class="sys_topnav sys_topnavDropdown"><a href="@node.Path" class="@linkClass" data-ajax-menu-path="/SiteElements/Menu/[email protected]">@node.Title</a>
<div class="sys_dropdown">
</div>
</li>
}
else if(node.Data.MD_Portals == true && node.Data.MD_NoDropdown == false)
{
<li class="sys_topnav sys_topnavDropdownPortals"><a href="@node.Path" class="@linkClass" data-ajax-menu-path="@node.Path">@node.Title</a>
<div class="sys_dropdown">
</div>
</li>
}
else {
<li class="sys_topnav"><a href="@node.Path" class="@linkClass" data-ajax-menu-path="/SiteElements/Menu/[email protected]">@node.Title</a></li>
}
}
}
}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment