Forums / Setup & design / Fetching an image from related objects of different kind
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?
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 :)