November Happy Hour will be moved to Thursday December 5th.

IContentLoader returns different page types when filtering for the start page

Vote:
 

I'm trying to get the start page 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?

#278430
Apr 13, 2022 15:25
Vote:
 

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);
#278433
Apr 13, 2022 16:53
Vote:
 

Hi,

It looks like what's going on in the first scenario is that you were retrieving all of the child pages of the start page rather than the start page itself. If you're after just the start page of the current site you're viewing you can do something like this:

var startPage = contentLoader.Get<StartPage>(ContentReference.StartPage);
#278434
Apr 13, 2022 17:02
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.