alexander helsinghof
alexander helsinghof

Reputation: 57

EPiServer 7 GetChildren for a specific page. and list all under that page

I'm having problems with EPiServer 7 trying to list childrens to a pagetype.

What I want is to get a page reference for the current page. I tried using PageReference listRoot = CurrentPage but it does not work.

My code looks like this:

    private IEnumerable<PageData> getChildren(EducationPage CurrentPage)
    {
        IEnumerable<PageData> pages = new List<PageData>(); 
        PageReference listRoot = CurrentPage;

        pages = contentLoader.GetChildren<PageData>(listRoot).OfType<PageData>();

        return pages;
    }

Upvotes: 1

Views: 5598

Answers (2)

Johan Kronberg
Johan Kronberg

Reputation: 1086

private IEnumerable getChildren(EducationPage CurrentPage)

It's not wise to name something own CurrentPage since many EPi classes exposes that property (unless you actually want to override it).

pages = contentLoader.GetChildren<PageData>(listRoot).OfType<PageData>();

You don't need the OfType-part and as stated by Andreas listRoot should be a PageReference.

Upvotes: 0

Andreas
Andreas

Reputation: 1355

I believe you need the CurrentPage.PageLink property:

PageReference listRoot = CurrentPage.PageLink;

Upvotes: 3

Related Questions