Iterating relation_list

Author Message

Felix Laate

Thursday 06 September 2007 5:25:57 am

Hi all,

I have a node of a class which has an attribute of type Object Relations. Now I want to make a <i>foreach</i>-loop iterating through those relations.

I tried this (simplified):

{foreach $node.data_map.images...relation_list as $image}
   {$image.name}
{/foreach}

but I get zippo (which would be nice if I were a serialsmoker).

I should know how to do this, but my head is working at half the speed of a C64, so I just can't remember.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Łukasz Serwatka

Thursday 06 September 2007 10:29:06 am

Hi Felix,

You need to access it via .content.relation_list of this attribute then make object fetch based on given object_id from relation_list Then you should see results.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

André R.

Thursday 06 September 2007 3:09:57 pm

Also remember to see if the node_id is set on the object you fetch, that way you can filter out objects that are placed in the trash..

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Felix Laate

Thursday 06 September 2007 3:56:21 pm

Thank you guys!

Will test this soonish .-)

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Bruce Morrison

Thursday 06 September 2007 5:29:12 pm

Here is a code snippit for those playing at home...

{foreach $node_content.data_map.rl_attribute.content.relation_list as $details}
   {def $rlt_node=fetch('content','node',hash('node_id',$details.node_id))}
   {if $rl_node}{node_view_gui view=line content_node=$rl_node}{/if}
   {undef $rl_node}
{/foreach}
my head is working at half the speed of a C64

You mean a VIC20 ;) ...ahh memories

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Xavier Dutoit

Friday 07 September 2007 10:13:02 am

Little warning: this becomes quite quite slow as soon as you have a lot of related objects. I'm not talking about felix brain, I'm talking about zillions of fetch/compile...

X+

http://www.sydesy.com

André R.

Friday 07 September 2007 10:58:34 am

That’s quite easy to fix, write a small template operator that takes care of the fetching by fetching all objects at once.

In the api you can fetch several nodes at once using:

eZContentObjectTreeNode:fetch

Or several objects at once using:

eZContentObject::fetchIDArray

The first one will skip trashed objects, and the last one will have main_node_id set to NULL if I remember correctly.

If you for some reason have waste amounts of relations, you should also let the operator handle paging.

{def $objects = multi_object_fetch( $node.data_map.rl_attribute.content.relation_list[, $offset = 0[, $limit = 10 ] ]  )}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Felix Laate

Friday 07 September 2007 12:34:46 pm

The Bruce-doctrine worked like a charm. But André's suggestion seems to be funnier, so I will try that approach as well.

By the way, the thing I'm working on is a gallery-template based on mootools.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.