SaaS CMS has officially launched! Learn more now.

Get all published language variants of a page


Hey all 

How do i get only a list of published langauges for a page (langauges that are available to front end user). 

var xxxxx = currentPage as ILocalizable;


Seems to return me all langauges even language's the page has only been created in although not published. 

currentPage.ExistingLanguages.Select(x => x.Name); is the same. 



Apr 01, 2020 15:47


Can you please try this-

var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var startPage = contentLoader.Get<StartPage>(ContentReference.StartPage);
var published = contentLoader.GetChildren<PageData>(startPage.ContentLink)
                                // skip container pages
                                .Filter(new FilterTemplate())
                                // skip unpublished pages
                                .Filter(new FilterPublished())
                                // ...


using EPiServer.Filters;


PageDataCollection myPages = GetChildren(myParentPage);
new FilterPublished(PagePublishedStatus.Published).Filter(myPages);

Edited, Apr 01, 2020 18:45
valdis - Apr 01, 2020 19:17
GetChildren() might not be the most optimal way to get other language branches for the current page. That method is travelling page tree..

Ive opted going down this route,

            var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
            var currentPageLanguages = availablePageLanguages.Select(page => page.Language.Name).ToList();
Apr 01, 2020 18:49
Ravindra S. Rathore - Apr 01, 2020 19:03
Glad you found the resolution

Not sure whether there is ready made method for this, but this could be the closest I could get to:

var pages = currentPage
    .Where(l => l != currentPage.Language)
    .Select(l => _loader.Get<StartPage>(currentPage.ContentLink.ToReferenceWithoutVersion(), l))
    .Where(p => p.Status == VersionStatus.Published);
Apr 01, 2020 19:15
Quan Mai - Apr 02, 2020 6:51
huh, StartPage?
valdis - Apr 02, 2020 8:48
don't copy AS-IS ;) just an example from my experiments with StartPage

An alternative is to use IContentVersionRepository, pseudo code:

var publishedVersions = currentPage.ExistingLanguages.Select(x => _contentVersionRepo.LoadPublished(currentPage.ContentLink, x.Name));

var published = _contentLoader.GetItems(publishedVersions.Select(x => x.ContentLink), new LoaderOptions()).OfType<YourContentType>();

Apr 02, 2020 6:53

and depending on your requirements you might need to exclude page in current language (if you are looking only for published pages in other languages).

Apr 02, 2020 8:49

@QUAN would your approach perform better than 

            var pageLanguagesBranches = contentRepository.GetLanguageBranches<PageData>(currentPage.ContentLink).ToList();
            var availablePageLanguages = FilterForVisitor.Filter(pageLanguagesBranches).OfType<PageData>();
            var currentPageLanguages = availablePageLanguages.Select(page => page.Language.Name).ToList();
Apr 02, 2020 9:06

There is no way to say for sure, unless you profile it. But 


gets each language branch individually, so if you have many languages, it looks like it will be slower than my suggestion

Apr 02, 2020 13:16
Minesh Shah (Netcel) - Apr 02, 2020 13:18
Thank you very much
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.