Navigate through related images

Author Message

Robert Malevic

Tuesday 18 November 2008 3:58:32 am

Hi All,

I need a template which should display related images one at the time.
I use this code to fetch related images and to display the first image:

{foreach $node.data_map.images.content.relation_list as $relatedImage}
    {def $obj=fetch('content', 'object',
                        hash('object_id', $relatedImage.contentobject_id))}
                        {attribute_view_gui attribute=$obj.data_map.image image_class='original'}         
    {undef $obj}
    {break}
{/foreach}

My problem is that in the loop above I need a break else all related images will be shown. What I want to do is fetch all related images, show the first image and add navigation to navigate through the other images.
I tried to access the related images separately but somehow I am only able to display all related images.

Any suggestions how to navigate through each related image separately?

Thanks!

Maxime Thomas

Tuesday 18 November 2008 11:53:29 pm

Hi,

I'm not sure your code is the best way to reach your aim.
I would have done this like this :

{def $count=$node.data_map.images.content.relation_list|count()
      $offset=0
      $object=''
}

{if $view_parameters.offset}
{set $offset=$view_parameters.offset}
{/if}

{def $obj=fetch('content', 'object',hash('object_id', $node.data_map.images.content.relation_list[$offset].contentobject_id))}
{attribute_view_gui attribute=$obj.data_map.image image_class='original'} 
{undef $obj}
{if $offset|gt(0)}
<a href="{$node.ul_alias|ezurl('no')}/(offset)/{$offset|dec()}">Previous</a>
{/if}

{if $offset|lt($count)}
<a href="{$node.url_alias|ezurl('no)}/(offset)/{$offset|inc()}">Next</a>
{/if}

Cheers

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Robert Malevic

Wednesday 19 November 2008 12:06:17 am

Hi Maxime,

Your solutions works and is exactly what I was looking for. Hopelfully more inexperienced programmers like me can benefit from it.

Thanks!!!

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 19:33:07
Script start
Timing: Jan 18 2025 19:33:07
Module start 'layout'
Timing: Jan 18 2025 19:33:07
Module start 'content'
Timing: Jan 18 2025 19:33:08
Module end 'content'
Timing: Jan 18 2025 19:33:08
Script end

Main resources:

Total runtime0.8963 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.0313152.6250
Module start 'layout' 0.00600.0023 741.656339.4609
Module start 'content' 0.00830.8868 781.1172540.8750
Module end 'content' 0.89510.0012 1,321.992212.1641
Script end 0.8963  1,334.1563 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.3828160.0002
Check MTime0.00130.1498160.0001
Mysql Total
Database connection0.00070.074310.0007
Mysqli_queries0.850794.9112570.0149
Looping result0.00050.0510550.0000
Template Total0.866196.620.4331
Template load0.00220.245020.0011
Template processing0.863996.390220.4320
Template load and register function0.00020.019710.0002
states
state_id_array0.00060.069210.0006
state_identifier_array0.00110.127720.0006
Override
Cache load0.00180.1982220.0001
Sytem overhead
Fetch class attribute can translate value0.00070.077020.0003
Fetch class attribute name0.00110.120840.0003
XML
Image XML parsing0.00080.085020.0004
class_abstraction
Instantiating content class attribute0.00000.001240.0000
General
dbfile0.00220.2501160.0001
String conversion0.00000.000840.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
3content/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/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.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: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs