Hi,
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())
// ...
.ToList();
or
using EPiServer.Filters;
....
PageDataCollection myPages = GetChildren(myParentPage);
new FilterPublished(PagePublishedStatus.Published).Filter(myPages);
Ive opted going down this route,
Not sure whether there is ready made method for this, but this could be the closest I could get to:
var pages = currentPage
.ExistingLanguages
.Where(l => l != currentPage.Language)
.Select(l => _loader.Get<StartPage>(currentPage.ContentLink.ToReferenceWithoutVersion(), l))
.Where(p => p.Status == VersionStatus.Published);
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>();
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).
@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();
There is no way to say for sure, unless you profile it. But
GetLanguageBranches
gets each language branch individually, so if you have many languages, it looks like it will be slower than my suggestion
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;
xxxxx.ExistingLanguages
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.
Thanks
Minesh