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!

  • Can you add the code you tried with views_embed_view? Does your view contain a filter for "Users current language"? – Laryn - CEDC.org Oct 22 '14 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, ...) " – Alex Trandafir Oct 22 '14 at 15:51
0

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

print views_embed_view($viewname, $display_id, $languagecode);
  • There is already a contextual filter for taxonomy; and it works fine. But not for language. Don't know why! – Alex Trandafir Oct 22 '14 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 - CEDC.org Oct 22 '14 at 16:41
  • Still not working :( – Alex Trandafir Oct 23 '14 at 7:59
  • What have you got for contextual filters, and what variables are you calling views_embed_view with? – Laryn - CEDC.org Oct 23 '14 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");"; – Alex Trandafir Oct 24 '14 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, privacy policy and cookie policy

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