Fetching an image from related objects of different kind

Author Message

Marc Boon

Friday 17 February 2006 8:40:20 am

I'm implementing a template for a summary view of a Article object, which can have various kinds of related objects, but I only want to show one related objects of type Image.
I was surprised that class_filter_type can not be used with fetch(content, related_objects).

This works:

{def $img=false()}
{section loop=fetch(content, related_objects, hash( object_id, $article.object.id))}
	{section-exclude match=true()}
	{section-include match=$:item.class_name|eq('Image')}
	{run-once}
		{set $img=$:item}
	{/run-once}
{/section}

But it seems rather cumbersome. Is there an easier way to do this?

Marc Boon

Sunday 19 February 2006 10:54:55 am

I found a simpler way:

{foreach $article.object.related_contentobject_array as $object}
{if $object.class_name|eq('Image')}
{def $img=$object}
{break}
{/if}
{/foreach}

I was a bit confused by the old-style and new-style syntax. Many examples use {section}, {default} and {let}, which seem all be deprecated. Being a PHP programmer, the new syntax looks a lot more familiar :)

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 22:26:01
Script start
Timing: Jan 18 2025 22:26:01
Module start 'layout'
Timing: Jan 18 2025 22:26:01
Module start 'content'
Timing: Jan 18 2025 22:26:02
Module end 'content'
Timing: Jan 18 2025 22:26:02
Script end

Main resources:

Total runtime0.7658 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0073 589.2891152.6563
Module start 'layout' 0.00730.0030 741.945339.5078
Module start 'content' 0.01030.7543 781.4531426.8828
Module end 'content' 0.76460.0011 1,208.33598.0938
Script end 0.7658  1,216.4297 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00290.3851160.0002
Check MTime0.00120.1626160.0001
Mysql Total
Database connection0.00170.221610.0017
Mysqli_queries0.724894.6436520.0139
Looping result0.00050.0628500.0000
Template Total0.726594.920.3632
Template load0.00250.321520.0012
Template processing0.724094.544020.3620
Template load and register function0.00010.018910.0001
states
state_id_array0.00110.139110.0011
state_identifier_array0.00090.119120.0005
Override
Cache load0.00210.2762170.0001
Sytem overhead
Fetch class attribute can translate value0.00050.061610.0005
Fetch class attribute name0.00080.106220.0004
XML
Image XML parsing0.00010.013410.0001
class_abstraction
Instantiating content class attribute0.00000.000720.0000
General
dbfile0.00060.0783100.0001
String conversion0.00000.001140.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
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 11
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs