IPageRetriever & culture

Sylvain C. asked on August 25, 2021 00:47

While redeveloping my site in Xperience and ASP.Net Core, I am facing issues regarding the culture. My site is bilingual in English and Spanish. My default culture is English. However, sometimes for one page, I have an english version but no spanish version. For an other page, I have only a Spanish version and no English version. In Kentico 12, to face this situation and display at least a page in the available culture, I was using the CombineWithAnyCulture() method.

Concerning, IPageRetriever, I have understood that it will show only the requested culture. Does it mean that I look for page in English but it is only in Spanish, I will get a 404 error if I use IPageRetriever instead of IDocumentQuery?

Thank you for clarifying this situation.

Sylvain

Correct Answer

Dmitry Bastron answered on August 25, 2021 10:44

Hi Sylvain,

The default behaviour of IPageRetriever in this case is the same as in IDocumentQuery - it's returning the current context culture only if nothing is specified. However, CombineWithAnyCulture() can also be used with IPageRetriever like this:

var homeSections = pageRetriever.RetrieveAsync<HomeSection>(
    query => query
        .Path(nodeAliasPath, PathTypeEnum.Children)
        .CombineWithAnyCulture()    // <= put it here
        .OrderBy("NodeOrder"),
    cache => cache
        .Key($"{nameof(HomeRepository)}|{nameof(GetHomeSectionsAsync)}|{nodeAliasPath}")
        .Dependencies((_, builder) => builder.PagePath(nodeAliasPath, PathTypeEnum.Children).PageOrder()),
    cancellationToken);
2 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.