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.

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

eZ debug

Timing: Jan 18 2025 18:37:51
Script start
Timing: Jan 18 2025 18:37:51
Module start 'layout'
Timing: Jan 18 2025 18:37:51
Module start 'content'
Timing: Jan 18 2025 18:37:52
Module end 'content'
Timing: Jan 18 2025 18:37:52
Script end

Main resources:

Total runtime1.2428 sec
Peak memory usage4,096.0000 KB
Database Queries71

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 589.1797152.6406
Module start 'layout' 0.00540.0034 741.820339.4766
Module start 'content' 0.00891.2324 781.2969630.0000
Module end 'content' 1.24130.0015 1,411.296916.1250
Script end 1.2427  1,427.4219 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.2508160.0002
Check MTime0.00130.1022160.0001
Mysql Total
Database connection0.00100.079910.0010
Mysqli_queries1.170894.2082710.0165
Looping result0.00060.0521690.0000
Template Total1.213297.620.6066
Template load0.00220.174320.0011
Template processing1.211097.445620.6055
Template load and register function0.00020.018410.0002
states
state_id_array0.00070.058310.0007
state_identifier_array0.00090.074420.0005
Override
Cache load0.00190.1513680.0000
Sytem overhead
Fetch class attribute can translate value0.00070.057430.0002
Fetch class attribute name0.00140.112780.0002
XML
Image XML parsing0.00060.050530.0002
class_abstraction
Instantiating content class attribute0.00000.003380.0000
General
dbfile0.00080.0633160.0000
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
20content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 44
 Number of unique templates used: 7

Time used to render debug report: 0.0003 secs