Page 1 of 1

Menu with forward/back and counter

Posted: Mon Feb 20, 2012 2:08 pm
by thomsonson
Hello all,

I am trying to work out the best way to implement a simple paginating menu in cmsms (back / forward links and a n of n counter). I know that the news and guestbook modules have this function built in, but for various reasons, I want to be able to do it with actual pages.

Ideally, this would be set up as the submenu, and it would be possible to cycle through all the child pages of a certain parent with the back & next links, and have the counter keep track of position.

I can't find a cms menu template which does this, and I have tried to put a solution together using the content_dump tag, but to no avail.. My strengths are rather more in design than coding, so any help or tips with this would be hugely appreciated :)

Re: Menu with forward/back and counter

Posted: Mon Feb 20, 2012 6:53 pm
by Dr.CSS
Maybe an image of what you want to do would help...

Re: Menu with forward/back and counter

Posted: Mon Feb 20, 2012 7:11 pm
by mcDavid
You can use {cms selflink} for that!
(optional) dir start/next/prev/up (previous) - Links to the default start page or the next or previous page, or the parent page (up). If this is used page should not be set.

Re: Menu with forward/back and counter

Posted: Mon Feb 20, 2012 7:58 pm
by calguy1000
it can also be done as a simple menu manager template...

you would just have to:
a: get the total count of the items (simple enough)
b: loop through the nodelist once to find the current node's index
{$node->current} indicates that IIRC.
c: do your smarty magic for your next/prev links:

Here is some (very loose) pseudocode.

Code: Select all

{foreach from=$nodelist item='node' name='nodelist'}
  {if $nodelist->current == true}
     {assign value='current_idx' value=$smarty.foreach.nodelist.index}
  {/if}
{/foreach}
{assign var='last_idx' value=$smarty.foreach.nodelist.total - 1}

{if $current_idx > 0}
  {* display link to previous page *}
  <a href="{$nodelist[$current_idx-1]->url}">prev<a>
{/if}
{if $current_idx < $last_idx}
  <a href="{$nodelist[$current_idx+1]->url}">prev</a>
  {* display link to next page *}
{/if}

Re: Menu with forward/back and counter

Posted: Tue Feb 21, 2012 3:39 pm
by thomsonson
thanks much for the replies, in the end i am using cgsimplesmarty as follows:

Code: Select all

{$cgsimple->get_sibling("prev","prev_sibling")}{if !empty($prev_sibling)}{cms_selflink page="$prev_sibling" text="Previous"}{/if}
<br>
{$cgsimple->get_sibling("next","next_sibling")}{if !empty($next_sibling)}{cms_selflink page="$next_sibling" text="Next"}{/if}
but I have 2 further questions..

1. how could one best construct a counter, as in page 2 of 4 for example, for the siblings pages. Is this possible with simplesmarty? or can the {$friendly_position} and {$count} tags be used in some way to count only the siblings of a certain page (rather than the entire menu)?

2. Could the code above be modified so that 'next' link stays visible on the final sibling page and links back to the first sibling (and vice versa at the other end)?