如何在 Kentico 中获取兄弟页面列表

How to get a list of sibling pages in Kentico

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

/
---Breads
-----Foo Bread
----------Recipe X
----------Nutrition A
---Cookies
-----Bar Cookie
----------Recipe Y
----------Nutrition B
-----Foo Cookie

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

如果您使用 CurrentDocument.NodeAliasPath,这将 return 您正在查看的当前文档,而您的 URL 将是

/Breads/Foo-Bread/Nutrition-A

所以你可以简单地使用:

CurrentDocument.Parent.NodeAliasPath + "/%"

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

我会说你想要在同一级别上获取当前文档父级的子级, 假设你有 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