Try our conversational search powered by Generative AI!

Get content that is available in the currently selected language?


We have a block that pulls in content and displays it on our page. Right now, no matter what language I select in our language switcher, this is not being honored by our block.

As I am new to EpiServer and C# I think I have identified the following line of code as being the one that pulls in the data?


Can I rewrite this to only get content in the language that is currently selected by the user?

Thank you for any help.

Feb 08, 2019 11:15

Check out this 

T Get<T>(
	ContentReference contentLink,
	CultureInfo language
Feb 08, 2019 11:41

Thanks I found that earlier while searching, but I am unsure with how to write the code.

Feb 08, 2019 11:44

You can start with this

Even better, take a Developer course with Episerver training 

Feb 08, 2019 11:50

That's so unhelpful. Thank you.

Feb 08, 2019 11:51


Why is it unhelpful to suggest that you take developer training course?

Feb 08, 2019 17:58

TBH what Quan provided is the best that can be found around internet.

Feb 25, 2019 3:55

I would like to provide feedback to the community:

We solved it by adding a filter to the find function. The code included a seach carried out by Episerver Find which was pulling in content of a specific category. But instead of honoring the current language it was pulling in everything.

To fix it, we changed this:

search = search.Filter(sp => sp.IsDeleted.Match(false))
                .OrderByDescending(sp => sp.PublishingDate, SortMissing.Last)

To this:

search = search.Filter(sp => sp.IsDeleted.Match(false))
                .OrderByDescending(sp => sp.PublishingDate, SortMissing.Last)
                .Filter(sp => sp.Language.Name.Match(ContentLanguage.PreferredCulture.Name))

So now we are pulling only content that matches the preferred culture.

Mar 04, 2019 11:02

If you are searching for IContentData you should only have to apply the .FilterForVisitor() filter. It's doing all filtering necessary for current visitor, eg access rights, published content, current language.

search = search.FilterForVisitor()
               .OrderByDescending(sp => sp.PublishingDate, SortMissing.Last)
Mar 04, 2019 14:09

Thanks for the tip, .FilterForVisitor() has exactly what's needed and would make the code far leaner. 

Mar 04, 2019 16:11
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.