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

eZ debug

Timing: Jan 18 2025 16:22:08
Script start
Timing: Jan 18 2025 16:22:08
Module start 'content'
Timing: Jan 18 2025 16:22:09
Module end 'content'
Timing: Jan 18 2025 16:22:09
Script end

Main resources:

Total runtime1.0489 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0107 587.8125180.8359
Module start 'content' 0.01070.9010 768.6484562.7109
Module end 'content' 0.91170.1371 1,331.3594336.7734
Script end 1.0488  1,668.1328 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.3842210.0002
Check MTime0.00140.1300210.0001
Mysql Total
Database connection0.00330.312110.0033
Mysqli_queries0.967192.20991940.0050
Looping result0.00190.17961920.0000
Template Total1.017097.020.5085
Template load0.00240.230820.0012
Template processing1.014596.726720.5073
Template load and register function0.00010.011810.0001
states
state_id_array0.00100.090610.0010
state_identifier_array0.00180.170720.0009
Override
Cache load0.00210.2020400.0001
Sytem overhead
Fetch class attribute can translate value0.00150.140430.0005
Fetch class attribute name0.00090.083850.0002
XML
Image XML parsing0.00460.435530.0015
class_abstraction
Instantiating content class attribute0.00000.001060.0000
General
dbfile0.00750.7155340.0002
String conversion0.00000.000530.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 26
 Number of unique templates used: 8

Time used to render debug report: 0.0002 secs