1

How do I load a view programmatically passing a language attribute? Tried with module_invoke and views_embed_view but none of them worked; Data is returned but not filtered by language;

Please advise. Thank you!

2
  • Can you add the code you tried with views_embed_view? Does your view contain a filter for "Users current language"?
    – Laryn
    Oct 22, 2014 at 15:46
  • To be more specific: I have a page view for news; when accessing the page directly from browser: "site/news" or "site/fr/news" - the content is rendered correctly. The problem appears when I try lo load this view programmatically. The English content is always being returned. Also, in "Filter Criteria" Section: " Content: Language (in Current user's language, ...) " Oct 22, 2014 at 15:51

2 Answers 2

0

If your view is set up with a Contextual Filter for language, this should work:

print views_embed_view($viewname, $display_id, $languagecode);
9
  • There is already a contextual filter for taxonomy; and it works fine. But not for language. Don't know why! Oct 22, 2014 at 15:57
  • You may want to clone the view display, add a contextual filter for language in the new display, remove the "Current user's language" filter for the new display, and then call this new display instead?
    – Laryn
    Oct 22, 2014 at 16:41
  • Still not working :( Oct 23, 2014 at 7:59
  • What have you got for contextual filters, and what variables are you calling views_embed_view with?
    – Laryn
    Oct 23, 2014 at 13:33
  • 1
    it works for language too; in contextual filters, at "Provide default value" choose "PHP Code" - for value, I used: "return array("fr", "und");"; Oct 24, 2014 at 7:59
0

I think you should add "Filter criteria-- Content:Language(current User's language.)". This will solve our problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.