Forums / Developer / display the related object of a related object

display the related object of a related object

Author Message

David Jones

Friday 15 September 2006 9:57:47 am

I have a related object on my page. It's basic; contains a title, a link, and a related image.

{let related_objects=fetch( 'content', 'related_objects',
				  		hash( 'object_id', $module_result.content_info.object_id ) )}
{section loop=$related_objects var=related_object}
	{if eq($related_object.content_class.identifier, "link_home_panel" )}
				  			


This fetches the related object and allows me to display the title and the link but I still need to access the related image.

I tried this

{let related_backgrounds=fetch( 'content', 'related_objects',
			hash( 'object_id', $related_object.content_info.object_id ) )}

	{section loop=$related_backgrounds var=related_background}
		{if eq($related_background.content_class.identifier, "image_home_panel" )}

 

Maybe I've just gone about selecting the object id wrong. Indeed when I try this

TEST: { $related_object.content_info.object_id}

all i get is TEST. ie no id.

Is this the correct approach?

Thanks



Claudia Kosny

Friday 15 September 2006 12:33:46 pm

Hello David

I haven't worked much with related objects before so I cannot give you any direct help. ut But generally you can use the attribute function to find out more about an object.
So in your first foreach just use an
{$related_object|attribute('show', 1)} to get a table of the direct attributes of this object. (Increasing the number in the second argument will give you more information as it shows the attributes of each attribute as well, read the docu for this operator)
Then you can access these attributes by calling $related_object.<name of the respective attribute>.

Using this approach you will most likely see that the object id you need is stored in $related_object.id.
In fact an contenobject does not have any attribute content_info, this is only for the moduele_result variable (which you should have see in the debug info so please check there the next time first).

Another good idea to find out which attributes hold what type of data is to check the documentation. The docu for contentobjects is here
http://ez.no/doc/ez_publish/technical_manual/3_8/reference/objects/ezcontentobject

So at the end I assume that you just have to replace

$related_object.content_info.object_id

with

$related_object.id

If that does help you to solve your problem post again, then I will check properly how to do what you want.

Greetings from Luxembourg

Claudia

Xavier Dutoit

Friday 15 September 2006 11:06:34 pm

Hi,

What I usually do is to create a view "related", and override it for the class(es) you need (eg image).

Then after having fetched the related objects:

{foreach $related as $object}
{node_view_gui view=related content_node=$object.main_node}
{/foreach}

And done.

X+

http://www.sydesy.com

David Jones

Monday 18 September 2006 2:22:17 am

Thanks Claudia but

$related_object.id

Doesn't return anything either.

I will take a look at working out how to create a view also.

Thanks for your persistent assistance

David Jones

Monday 18 September 2006 11:53:53 pm

X,

I been playing with your approach but not had much luck so far.

What does your "view" look like?

Many thanks

Claudia Kosny

Tuesday 19 September 2006 11:53:24 am

Hello David

I tried it now and it looks like there is already something strange going on in the first fetch.
I tried this for the first fetch (the 71 is my test object):

{def $inner_related_objects = ''
     $related_objects=fetch( 'content', 'related_objects', hash( 'object_id', 71))}
{foreach $related_objects as $related}
 {$related.name}<br />
 {set $inner_related_objects = fetch( 'content', 'related_objects', hash( 'object_id', $related.id,
                                                                           'all_relations', true()))}
 {foreach $inner_related_objects as $inner_related}
  {$inner_related|attribute('show', 2)}
 {/foreach}
{/foreach}

If $related.id is empty in your case you seem not to fetch an object which is pretty strange. So make sure that you do not have a typo in there somewhere. Please note that in the code above I had to use 'all_relations', true() in the inner fetch as I used a different type of relation there.

Claudia

David Jones

Wednesday 20 September 2006 4:40:15 am

Claudia , thanks so much,

You version works lovely,

Thank you for all your time.