【问题标题】:How to get a list of sibling pages in Kentico如何在 Kentico 中获取兄弟页面列表
【发布时间】:2018-12-13 21:23:06
【问题描述】:

我们有一个使用 Kentico CMS 的 MVC 应用程序。如何从内容树中的给定节点检索同级页面和子页面?比如说内容树看起来像

/
---Breads
-----Foo Bread
----------Recipe X
----------Nutrition A
---Cookies
-----Bar Cookie
----------Recipe Y
----------Nutrition B
-----Foo Cookie
  • 当访问者在营养 A 页面上时,他们应该会在侧栏上看到食谱 X
  • 当用户在食谱 Y 页面上时,他们应该在侧栏上看到营养 B
  • 如果他们在 Cookies 页面上,他们应该会在侧栏上看到 Bar Cookie 和 Foo Cookie 等等。

我发现一些示例使用宏,但我认为我不能在 MVC 中使用它。

【问题讨论】:

    标签: asp.net-mvc kentico


    【解决方案1】:

    我想说你想让当前文档父级的子级处于同一级别, 假设你有CurrentDocument:

        var docs = DocumentHelper
            .GetDocuments()
            .OnSite("CorporateSite")
            .Culture("en-US")
            .Where(d => d.NodeParentID == CurrentDocument.NodeParentID && d.NodeLevel == CurrentDocument.NodeLevel)
            .OrderBy(d => d.DocumentName);
    
        // Go through the documents 
        foreach (var document in docs)
        {
            Response.Write(HTMLHelper.HTMLEncode(document.DocumentName) + "<br />");
        }
    

    阅读更多DocumentHelper

    【讨论】:

    • 当您已经按 NodeParentID 过滤时,为什么还要在节点级别过滤?
    • 只是为了确定,因为它可能会带来所有孩子,即孩子的孩子等。
    【解决方案2】:

    如果您使用CurrentDocument.NodeAliasPath,这将返回您当前所在的文档,并且您的 URL 将是

    /Breads/Foo-Bread/Nutrition-A

    所以你可以简单地使用:

    CurrentDocument.Parent.NodeAliasPath + "/%"

    作为您在 API 调用中的路径。

    【讨论】:

    • 无论我在哪个页面上,父对象都返回 null。
    猜你喜欢
    • 1970-01-01
    • 2018-09-19
    • 2011-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 1970-01-01
    相关资源
    最近更新 更多