Total Label
| From: | Pete Morganic | Date: | Mon, 10 Mar 2003 16:03:47 +0000 |
| Subject: | Total Label | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-8532@lists.php.net to get a copy of this message | ||
Would it be possible to have a $smarty.section.totalcaption modifier..
I'm already using a plugin called numbertext
eg
{$smarty.section.sites.total|numbertext:"No sites":"One site":"%d sites"}
in my dreams
{$smarty.section.sites.totalcaption:"No sites":"One site":"%d sites"}
it could be called totallabel, totalcaption and also have a default of "No Items":"One Item":"%d items"
--------------------------------------------
<?php
/*
* Smarty plugin
* --------------------------------------------------------------------------
* File: modifier.numbertext.php * Type: modifier * Name: numbertext* Version: 1.01
* Date: April 21, 2002* Purpose: Outputs alternative text to numeric variables.
* Example:
* {$number_of_records|numbertext:"no records":"one record":"%d records"}
* If $number_of_records==0 it outputs 'no records'
* If $number_of_records==1 it outputs 'one record'
* If $number_of_records==34 it outputs '34 records'
* Install: Drop into the plugin directory.
* Author: Andreas Heintze <andreas.heintze@home.se>
* --------------------------------------------------------------------------
*/
function smarty_modifier_numbertext()
{
$alt_array = func_get_args();
if (is_numeric($value = $index = $alt_array[0])) {
$index++;
$n = count($alt_array)-1;
$index = $index>$n?$n:$index;
$index = $index<1?1:$index;
return str_replace("%d", $value, $alt_array[$index]);
}
else {
return $index;
}
}
?>