Forums / Developer / Fetch filter based on current language

Fetch filter based on current language

Author Message

Lo' F.

Thursday 04 November 2010 11:58:23 am

Hi guys,

in a fetch tree statement, as the one below, is there a filter I can set to retrieve the current language translated version of the articles only?

{def $items=fetch('content', 'tree', hash('parent_node_id', 2, 'class_filter_type', 'include', 'class_filter_array', array('article')))}

tried ..

{def $language=fetch('content', 'locale')}
{def $items=fetch('content', 'tree', hash('parent_node_id', 2, ..., 'locale_code', $language.locale_code))}

but it doesn't filter the articles based on their language translation...

Please, tip me off! Thx!

loredanaebook.it

Philippe VINCENT-ROYOL

Friday 05 November 2010 1:36:50 am

Hi,

Use 'language' parameters with your current language

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Modules/content/Fetch-functions/tree

Cheers

Certified Developer (4.1): http://auth.ez.no/certification/verify/272607
Certified Developer (4.4): http://auth.ez.no/certification/verify/377321

G+ : http://plus.tl/dspe
Twitter : http://twitter.com/dspe

Lo' F.

Sunday 07 November 2010 10:30:39 am

Hi Philippe,

As for what I asked, the following works just great, thank you!

{def $language=fetch('content', 'locale')}
{def $items=fetch('content', 'tree', hash('parent_id_node', 2, ..., 'language', $language.locale_code))}
{foreach $items as $item}
  ...
{/foreach}

...

But I also tumbled to there is a better and easier way to prevent the objects from being displayed if their content isn't translated in the current siteaccess language.

When I ..realized that what I actually need had more to do than just filtering the article's objects, and needed instead to be applied to all the untranslated objects of the entire site, this other solution has made the things more ..easy-peasy (..besides helped me to better understand some site.ini settings' concepts):

On a first step (.. please, feel free to correct me if I miss something or tell something wrong..), for each siteaccess set the locale's language and the objects content's language. In the language list specify the only locale language giving no options if the translation doesn't exsist.

/settings/siteaccess/[fre]/site.ini.append.php

[SiteSettings]
...
SiteURL=localhost/index.php/fre
...

[RegionalSettings]
Locale=fre-FR
ContentObjectLocale=fre-FR
SiteLanguageList[]
SiteLanguageList[]=fre-FR
TextTranslation=enabled

In the admin back-end, then, Content structure tab, select the node, Translations tab, and uncheck "Use the main language if there is no prioritized translation" checkbox.

p.s. If, at first, you get a kernel error (object not found), it might be bacause the template_look.tpl has no other version than the main language.
If this is the case, go to Design tab, look and feel, and make a new translation based on the exsisting one.

loredanaebook.it