previous / next - fetch

Author Message

fabian schoen

Monday 13 November 2006 8:56:34 am

Hi

Maybe I overseen it in the documentation, but is there an easy implementation of a next/previous navigation?

I created an own template which performs a fetch to get 7 (for example) node objects. The first one (A) is shown on the screen. Now I would like to implement the function to use a "next" link to go to the next node (B).
Do I have to perform a second fetch or can I read it from an attribute, which one is the next and which is the previous one?

thanks
fabian
3.6.10

Georg Franz

Monday 13 November 2006 10:14:58 am

Hi,

yes, in an image template, there is an prev / next code, but it contains a bug:
http://issues.ez.no/IssueView.php?Id=9160&activeItem=6

design/base/templates/override/full/image.tpl

It is working if you don't sort the items in the folder by name.

If you need to sort the items by name, there is a workaround:

{def $content_list=fetch( content, list, hash( parent_node_id, $node.parent_node_id,
                                                sort_by, $node.parent.sort_array ) )
     $current_pos=0
     $previous_image=false()
     $next_image=false()
     $content_count=$content_list|count}
{foreach $content_list as $key => $item}
	{if eq($item.node_id,$node.node_id)}{set $current_pos=$key}{/if}
{/foreach}
{if $content_count|gt(1)}
	{if $current_pos|gt(0)}{set $previous_image=array($content_list[sub($current_pos,1)])}{else}{set $previous_image=array($content_list[sub($content_count,1)])}{/if}
	{if sum($current_pos,1)|lt($content_count)}{set $next_image=array($content_list[sum($current_pos,1)])}{else}{set $next_image=array($content_list[0])}{/if}
{/if}

But this code isn't good because you need to fetch each element in the list to find out which is previous and which is next.

Hope that helps.

Best wishes,
Georg.

--
http://www.schicksal.com Horoskop website which uses eZ Publish since 2004

fabian schoen

Monday 13 November 2006 1:46:24 pm

Thanks Georg. Works

regards
fabian

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.