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.

eZ debug

Timing: Jan 31 2025 06:11:53
Script start
Timing: Jan 31 2025 06:11:53
Module start 'content'
Timing: Jan 31 2025 06:11:53
Module end 'content'
Timing: Jan 31 2025 06:11:53
Script end

Main resources:

Total runtime0.1361 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 588.0625180.8125
Module start 'content' 0.00520.0061 768.8750102.0547
Module end 'content' 0.01130.1247 870.9297531.8750
Script end 0.1360  1,402.8047 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00292.1138200.0001
Check MTime0.00120.8552200.0001
Mysql Total
Database connection0.00070.546010.0007
Mysqli_queries0.093168.43151410.0007
Looping result0.00110.78031390.0000
Template Total0.124491.510.1244
Template load0.00080.556310.0008
Template processing0.123790.895110.1237
Override
Cache load0.00050.377810.0005
Sytem overhead
Fetch class attribute can translate value0.00050.396210.0005
XML
Image XML parsing0.00020.147910.0002
General
dbfile0.00956.9464200.0005
String conversion0.00000.002830.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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs