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

{section} next item

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
tadeu_fo
Smarty n00b


Joined: 21 Nov 2004
Posts: 4
Location: Aracaju, Brazil

PostPosted: Sun Nov 21, 2004 12:26 am    Post subject: {section} next item Reply with quote

Hi everybody I was trying to arrange an array as a table with 2 colums in such way that the dedigner could use without much programming.
But I could not find a way to do it without complex(using {math}) programming. So I made a section_next plugin that jumps next item on a section Wink .
Here it is:
save it as function.section_next.php in your plugins folder.
Code:

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


/**
 * Smarty {section_next} function plugin
 *
 * Type:     function<br>
 * Name:     section_next<br>
 * Author:   Tadeu Ferreira Oliveira
 * Contact:  tadeu_fo@yahoo.com.br
 * Purpose:  jump to the next element in a section
 * @param array parameters
 * @param Smarty
 * @return null
 */
function smarty_function_section_next($params, &$smarty)
{

    if (!isset($smarty->_sections[$params["name"]])){
      $smarty->trigger_error("section_next: section '".$params["name"]."' not found");
        return;
   }   
   $smarty->_sections[$params["name"]]['index']       += $smarty->_sections[$params["name"]]['step'];
   $smarty->_sections[$params["name"]]['iteration']++;
   $smarty->_sections[$params["name"]]['rownum']       = $smarty->_sections[$params["name"]]['iteration'];
   $smarty->_sections[$params["name"]]['index_prev']    = $smarty->_sections[$params["name"]]['index'] - $smarty->_sections[$params["name"]]['step'];
   $smarty->_sections[$params["name"]]['index_next']    = $smarty->_sections[$params["name"]]['index'] + $smarty->_sections[$params["name"]]['step'];
   $smarty->_sections[$params["name"]]['first']         = ($smarty->_sections[$params["name"]]['iteration'] == 1);
   $smarty->_sections[$params["name"]]['last']          = ($smarty->_sections[$params["name"]]['iteration'] == $smarty->_sections[$params["name"]]['total']);
}

/* vim: set expandtab: */

?>
[/list]
Back to top
View user's profile Send private message Send e-mail
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 -> 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