10 * Smarty {counter} function plugin
14 * Purpose: print out a counter value
15 * @link http://smarty.php.net/manual/en/language.function.counter.php {counter}
16 * (Smarty online manual)
17 * @param array parameters
21 function smarty_function_counter($params, &$smarty)
23 static $counters = array();
25 $name = (isset($params['name'])) ?
$params['name'] : 'default';
26 if (!isset($counters[$name])) {
27 $counters[$name] = array(
34 $counter =& $counters[$name];
36 if (isset($params['start'])) {
37 $counter['start'] = $counter['count'] = (int)$params['start'];
40 if (!empty($params['assign'])) {
41 $counter['assign'] = $params['assign'];
44 if (isset($counter['assign'])) {
45 $smarty->assign($counter['assign'], $counter['count']);
48 if (isset($params['print'])) {
49 $print = (bool)$params['print'];
51 $print = empty($counter['assign']);
55 $retval = $counter['count'];
60 if (isset($params['skip'])) {
61 $counter['skip'] = $params['skip'];
64 if (isset($params['direction'])) {
65 $counter['direction'] = $params['direction'];
68 if ($counter['direction'] == "down")
69 $counter['count'] -= $counter['skip'];
71 $counter['count'] +
= $counter['skip'];
77 /* vim: set expandtab: */