Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty Pagination Function

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
doge
Smarty n00b


Joined: 03 Dec 2019
Posts: 3

PostPosted: Thu Dec 12, 2019 5:10 am    Post subject: Smarty Pagination Function Reply with quote

Help me on error cause paginator function.

I made this function in smarty

Code:
<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {paginator} function plugin
 *
 * Type:     function<br>
 * Name:     paginator<br>
 * Purpose:  create pages links<br>
 * @param array
 * @param Smarty
 */
function smarty_function_paginator($params, &$smarty)
{
  $col = $params['col'];
  $cur = $params['cur'];
  $url = $params['url'];
  $delta = $params['delta'] ? $params['delta'] : 5;

  echo '<div class="pages">';
  if ($cur > 2)
    echo '<a href="' . sprintf($url, 1) .'" class="first">&lt;&lt;&lt;</a>';
  if ($cur > 1)
    echo '<a href="' . sprintf($url, $cur-1) .'" class="prev">&lt;&lt;</a>';

  $start = $cur - $delta;
  if ($start < 1) $start = 1;
  $end = $cur + $delta;
  if ($end > $col) $end = $col;

  for ($i = $start; $i <= $end; $i++) {
    if ($i == $cur) {
      echo '<b>'.$i.'</b>';
    } else {
      echo '<a href="' . sprintf($url, $i) .'" class="page">'.$i.'</a>';
    }
  }

  if ($cur < $col-1)
    echo '<a href="' . sprintf($url, $cur+1) .'" class="prev">&gt;&gt;</a>';
  if ($cur < $col)
    echo '<a href="' . sprintf($url, $col) .'" class="first">&gt;&gt;&gt;</a>';
  echo '</div>';

  return;
}

/* vim: set expandtab: */

?>


In index.php I set like this

Code:
$groupspages = array(
    "cur" => $pages,
    "onpage" => $pagination,
    "col" => 3
);
$smarty->assign('pages', $groupspages);


Then in my template I call it

Code:
{paginator col=$pages.col cur=$pages.cur}


But seems nothing work here, can anybody help me?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General 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