Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Using LanguageSelector parameter in GetChildren method in Episerver 8

Vote:
 

Hello,

We recently upgraded our project to Episerver 8, and I read about the changes to content loading here: http://world.episerver.com/documentation/Items/Upgrading/EPiServer-CMS/8/Breaking-changes/changes-to-content-loading-in-cms-8/

In one part of our code, we need to find pages of a certain type, including unpublished and archived pages. The only way we figured out how to do that was by adding the LanguageSelector.Autodetect(true) parameter, like so:

var eventPages = contentRepository.GetChildren(startPage.EventsRoot, LanguageSelector.AutoDetect(true));

Is this still the recommended way to get pages regardless of publish status? I thought that the LanguageSelector was deprecated, but it still seems to be working in the GetChildren method anyway.

/John

#120723
Apr 23, 2015 11:18
Vote:
 

Hi

The equivalent call using LoaderOptions would be:

var eventPages = contentRepository.GetChildren<EventPage>(startPage.EventsRoot, new LoaderOptions{ LanguageLoaderOption.FallbackWithMaster() });

You can still use static methods on LanguageSelector if you prefer that, they will "under the hood" create a LoaderOptions instance as above. So basically is the static methods on LanguageSelector now convenient methods to create LoaderOptions with different LanguageLoaderOption. 

However if you write tests for your code I would suggest to use LanguageLoaderOption instead since they are easier to handle in that scenario and the static methods of LanguageSelector.

The main reason LoaderOptions where introduced (as a replacement to ILanguageSelector) was to make it possible to pass in other LoaderOption instances as well. (Currently there is also a ProjectLoaderOption and others might come).

#120805
Apr 24, 2015 14:38
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.