Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

PLUGIN: smarty textblock paginate

Post new topic   Reply to topic    Smarty Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
Smarty Rookie

Joined: 30 Jan 2004
Posts: 10

PostPosted: Thu May 06, 2004 3:54 am    Post subject: PLUGIN: smarty textblock paginate Reply with quote

This is my first smarty plugin that i've written while working on my mini CMS.

its very effective and simple for spliting big article into smaller chunks and creating navigation menu between them :

 * Smarty plugin
 * -------------------------------------------------------------
 * File:     block.paginate.php
 * Type:     block
 * Name:     paginate
 * Purpose:  paginate content
 * -------------------------------------------------------------
function smarty_block_paginate($params, $content, &$this)
  if (is_null($content)) {
  if (!isset($page_name)) $page_name='page';
  if (!isset($split_name)) $split_name='<NEWPAGE>';
  if (isset($get_params[$page_name])) $current_page=$get_params[$page_name];

  $Pages = explode( "$split_name", $content );
  $TotalPages = sizeof( $Pages );

  if ($TotalPages== 1)
   return $content;
   if (!$current_page) $current_page = 1;

   foreach ($get_params as $key => $value)
    if ($key != "$page_name")
   while ($i <= $TotalPages)
    $linkage.=($i==$current_page)?"[<b>$i</b>]":"<a href='$script?".$link_params.$page_name."=".$i."'>$i</a>";


   return $Pages[$current_page-1].$linkage;



$smarty->assign('myarticle','first page contents<NEWPAGE>second page contents <NEWPAGE>ETC');
{paginate script_name="$SCRIPT_NAME" get_params=$smarty.get} $myarticle {/paginate}

* $SCRIPT_NAME & $smarty.get are required in order to create links.
* $split_name is optional parameter: defines the string separator used in this plugin to split article in smaller chunks (default -> "<NEWPAGE>")
*$page_name - optional parameter: how do you want your pages to be called (default -> "page")

If you want to split your article using <LDFJSLDS> instead of <NEWPAGE> and want for pagination to use "row" instead of default "page" - then use it as follows:

{paginate script_name="$SCRIPT_NAME" get_params=$smarty.get split_name="<LDFJSLDS>" page_name="row"}
first page content<LDFJSLDS>second page content <LDFJSLDS> third page content and so on

i'm using it here:

it will keep GET variables intact

for example if i link to the same article with some extra variables

it will preserve them.

i guess could be improved to give a choice of navigation menus
1) << <> >>
2) (first) next [current] previous (last)
3) numeric (as is now)
4) something else...

feedback appreciated
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Plugins All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP