how to get localized content by document query?

Muhammad Kaleem asked on May 23, 2019 10:19

i'm using kentico12 mvc, i'm getting multiple documents, also i have enabled multiple cultures, please suggest how can i get localized data from documents, currently i'm using this query, please suggest

thanks

MultiDocumentQuery pages = DocumentHelper.GetDocuments()
                                .Path("/Home", PathTypeEnum.Children)
                                .OnSite(SiteContext.CurrentSiteName)
                                .Culture("en-us");

Recent Answers


Brenden Kehren answered on May 23, 2019 13:02

The document query you have written will get all documents below the /home page for the "en-US" culture of any page type. What it looks like you are missing is this:

.CombineWithDefaultCulture(false)

I believe this is true by default.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 13:46

thanks Brenden, i'll try and let you know about status...

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 19:48 (last edited on May 23, 2019 19:49)

hi Brenden, i have access all the documents by above MultiDocumentQuery but unable to access data of documents please suggest, my sample code is here, i want to get data from page fields, please suggest...

Thanks

MultiDocumentQuery pages = DocumentHelper.GetDocuments()
                                .Path("/News", PathTypeEnum.Children)
                                .OnSite(SiteContext.CurrentSiteName)
                                .OrderBy("NodeOrder")
                                .Culture(LocalizationContext.CurrentCulture.CultureCode)
                                .Published(true);
if(pages != null && pages.Count > 0)
                {
                    foreach(TreeNode item in pages)
                    {
            //here i' checking class name of document because there are multiple documents of different type
                        if(item.ClassName == "CMS.News")
                        {
                if(item.GetValue("Title") != null && item.GetValue("Title").ToString() != "")
                            {
                                strTitle = item.GetValue("Title").ToString();
                            }
            }
            }
        }
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 23, 2019 20:07

Use this in your document query as well:

.WithCoupledColumns();

You might want to check out some of the Document Query documentation. It may be for version 8 but still relevent.

0 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 23, 2019 21:48

thanks Brenden,

i have added .Type("CMS.ClassName", q => q.Default())` in query and its working fine now

1 votesVote for this answer Mark as a Correct answer

Muhammad Kaleem answered on May 27, 2019 13:14

hi brenden, i'm unable to access localized content by .CombineWithDefaultCulture(false) when i go from

"abc.com/en-Us" to "abc.com/ar-KW" it does not show my localized data, still showing "en-US" data please suggest

thanks

0 votesVote for this answer Mark as a Correct answer

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