joym8
joym8

Reputation: 4212

How to get a list of sibling pages in Kentico

We have a MVC application that uses Kentico CMS. How can I retrieve sibling pages and child pages from a given node in content tree? Say for instance content tree looks like

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

Some examples I found use macros and I don't think I can make use of that in MVC.

Upvotes: 1

Views: 721

Answers (2)

Peter Mogilnitski
Peter Mogilnitski

Reputation: 998

I'd say you want get children of the current document parent on the same level, let say you have 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 />");
    }

Read more on DocumentHelper

Upvotes: 2

Brenden Kehren
Brenden Kehren

Reputation: 6117

If you use CurrentDocument.NodeAliasPath, this will return the current document you're on and your URL would be

/Breads/Foo-Bread/Nutrition-A

So you can simply use:

CurrentDocument.Parent.NodeAliasPath + "/%"

as your path in your API call.

Upvotes: 0

Related Questions