Adding previous and next links to the modules detail pages

  Previous article Next article  

Adding previous and next links to the modules detail pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1
  Last updated: 18-11-2017
  Comments: 0
  http://cms.ms/4xjt

This tutorial demonstrates the power and simplicity of Smarty template code by using it to add previous and next buttons to the CMS Made Simple™ News module without any UDT.

The method described here originates from the IDT blog and was written by Manuel in 2012. The tutorial there doesn't work anymore with the latest CMSMS™ releases due to the Smarty scope settings. Beside that the original tutorial was written for the CGBlog module and the next-prev buttons are now included in the module package as you can see here at CMS can be Simple.org.

This updated tutorial will show you the same method that works in the new CMS Made Simple 2.x series, but for modules like the News, Company Directory and others! You might need to change some Smarty variables like $the_entry->moreurl to get the correct URL for that module.

  How to use

Create a new News summary template, named "prev_next_links", with the content:

{foreach from=$items item=the_entry}
  {capture append='allIDs'}{$the_entry->id}{/capture}
  {capture append='allURLs'}{$the_entry->moreurl}{/capture}
{/foreach}

{foreach from=$allIDs item=someID name=findmyID}
  {if $currentID == $someID}{$currentkey = $smarty.foreach.findmyID.index}{/if}
{/foreach}

<p class="next-button">
  {$nextkey = $currentkey+1}
  {if isset($allURLs[$nextkey])}
    <a href="{$allURLs[$nextkey]}">Next article</a>&nbsp;&gt;
  {/if}
</p>

<p class="prev-button">
  {$prevkey = $currentkey-1}
  {if isset($allURLs[$prevkey])}
    &lt;&nbsp;<a href="{$allURLs[$prevkey]}">Previous article</a>
  {/if}
</p>

In the detail template of the module you should add these lines at the spot you want to have the buttons in the template:

{$currentID = $entry->id scope=global}
{News summarytemplate='prev_next_links'}


  Working example





CMS Made Simple 2.2.5 - Tutorials, tips and tricks - CMSMS 2.2.5

Adding previous and next links to the modules detail pages

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.1
  Last updated: 18-11-2017
  Comments: 0
  http://cms.ms/4xjt