Forums / Setup & design / Control output of object relations

Control output of object relations

Author Message

Stephen Martin

Monday 03 March 2008 3:35:53 pm

New user question. I've created a class called "animal" and am using a object relations to store images associated with the animal.

Using the code below I can output the photos, however, I'd like to output just the first photo instead of all of them. I've searched the forum carefully but cannot find a proper solution. Please advise. Thanks!

		{def $nodes=fetch( 'content', 'list',
        hash( 'parent_node_id', 59,
              'depth', 1 ) )}
 		{foreach $nodes as $node}
			<div id="animal-listing">
				<div id="animal-head">
					<h1>{$node.name|wash} {attribute_view_gui attribute=$node.object.data_map.genestar_rating}/{attribute_view_gui attribute=$node.object.data_map.genestar_rating_max} <img style="vertical-align:middle" src={'genestar-logo.gif'|ezimage()} alt="GeneStar Logo" /></h1>
					<div id="price">{attribute_view_gui attribute=$node.object.data_map.price}</div> {* price *}
				</div> {* animal-head *}
				<div id="animal-photo">
					{attribute_view_gui attribute=$node.object.data_map.photography}
				</div> {* animal-photo *}
			</div> {* animal-listing *}
		{/foreach}

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

eZ debug

Timing: Jan 18 2025 04:26:45
Script start
Timing: Jan 18 2025 04:26:45
Module start 'content'
Timing: Jan 18 2025 04:26:46
Module end 'content'
Timing: Jan 18 2025 04:26:46
Script end

Main resources:

Total runtime0.8434 sec
Peak memory usage4,096.0000 KB
Database Queries207

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0050 592.9453180.8281
Module start 'content' 0.00500.6947 773.7734660.8672
Module end 'content' 0.69970.1437 1,434.6406341.0859
Script end 0.8433  1,775.7266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.4954210.0002
Check MTime0.00160.1839210.0001
Mysql Total
Database connection0.00040.050410.0004
Mysqli_queries0.762390.38112070.0037
Looping result0.00220.26642050.0000
Template Total0.818897.120.4094
Template load0.00190.226020.0010
Template processing0.816996.857220.4085
Template load and register function0.00040.047510.0004
states
state_id_array0.00100.118610.0010
state_identifier_array0.00110.124620.0005
Override
Cache load0.00160.1896330.0000
Sytem overhead
Fetch class attribute can translate value0.00200.239950.0004
Fetch class attribute name0.00260.304690.0003
XML
Image XML parsing0.00220.260950.0004
class_abstraction
Instantiating content class attribute0.00000.003390.0000
General
dbfile0.00270.3196400.0001
String conversion0.00000.000630.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 22
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs