csharp 顶级菜单导航剃须刀,允许用户使用元数据标签设置他们想要显示的页面。还显示下一级别。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 顶级菜单导航剃须刀,允许用户使用元数据标签设置他们想要显示的页面。还显示下一级别。相关的知识,希望对你有一定的参考价值。

@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>

以上是关于csharp 顶级菜单导航剃须刀,允许用户使用元数据标签设置他们想要显示的页面。还显示下一级别。的主要内容,如果未能解决你的问题,请参考以下文章

顶级导航下拉菜单问题

织梦一二级导航菜单被点击顶级栏目高亮(加class)解决方法

织梦DEDECMS调用导航栏的顶级栏目二级栏目及三级栏目

SpriteKit,创建一个位于所有场景之上的导航菜单

SwiftUI:contextMenu 菜单

在引导导航菜单中将用户图标向右移动