ernest
ernest

Reputation: 1724

EpiServer - IContentLoader returns different page types when filtering for the start page

I'm trying to get the start pages in Razor code so I can display different navs based on the start page. Here's how I'm doing it:

var contentLoader = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IContentLoader>();
var pages = contentLoader.GetChildren<PageData>(ContentReference.StartPage);

This is what shows up in the debugger. I was expecting to only see pages of type, Start. But I'm seeing Hero pages and everything. Any ideas what's going on here?

enter image description here

Upvotes: 0

Views: 711

Answers (2)

Marcus &#197;berg
Marcus &#197;berg

Reputation: 213

If you want to get the start page (just one instance) and it is the same start page that is selected as start page in admin mode for the configuration of your site you should do the following

var startPage = contentLoader.Get<StartPage>(ContentReference.StartPage);

Upvotes: 1

ernest
ernest

Reputation: 1724

I was able to resolve this by passing in the ContentReference for the root page and my start page object.

var pages = contentLoader.GetChildren<namespace.StartPage>(ContentReference.RootPage);

Upvotes: 0

Related Questions