Share » Forums » Setup & design » Control output of object relations

Control output of object relations

Control output of object relations

Monday 03 March 2008 3:35:53 pm - 5 replies

Author Message

Felix Laate

Tuesday 04 March 2008 12:37:50 am

Hi Stephen,

if you want he first image (dependning on the sorting):

{def $nodes=fetch( 'content', 'list',
                              hash( 'parent_node_id', 59,
                             'depth', 1,
                              'limit',1 ) )}

Or do you have other criteria?

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Stephen Martin

Tuesday 04 March 2008 8:39:38 am

Felix,

Thanks for your answer. It wasn't quite was I was looking for. Adding the limit does return one record, however, I'm looking to return the first image of an object relation. So, if I put the limit of 1 in there, I get just one record returned whereas I'd like all records (animals) displayed with the first related photo.

$node.object.data_map.photography is an object relations that contains multiple photos. I need a way to get just the first image out of it.

Hopefully that is clearer.

Thanks!

Xavier Dutoit

Wednesday 05 March 2008 4:41:19 am

{$node.object.data_map.photography|attribute(show,2)}

Will help you finding what you want

http://www.sydesy.com

Stephen Martin

Thursday 06 March 2008 9:11:47 am

Xavier,

Thanks for the reply. That tip helped me figure it out. Don't know if this is the most efficient solution, but this is the code:

{foreach $node.data_map.photography.content.relation_list as $relation}
     {def $obj=fetch('content', 'object',
			hash('object_id', $relation.contentobject_id))}
			{attribute_view_gui attribute=$obj.data_map.image image_class='medium'}		
	{undef $obj}
	{break}
{/foreach}

André R.

Thursday 06 March 2008 9:56:04 am

That will do fine, but just so you know it this will contain objects in the trash as well.
In newer eZ Publish versions there is attribute on the relation called ''in_trash" or something.
On older versions (and new ones) it is visible on the main_node_id of the object you fetch (it will be false / null / empty).

One alternative to looping over the relations list is to use the fetch('content', 'relation') (see doc).

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

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu