Re: [SMARTY] Total Label

From: Date: Mon, 10 Mar 2003 16:41:42 +0000
Subject: Re: [SMARTY] Total Label
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-8536@lists.php.net to get a copy of this message
check those repositories first :-) http://smarty.php.net/contribs/plugins/view.php/modifier.numbertext.php On Mon, 2003-03-10 at 10:03, Pete Morganic wrote: > 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; > } > } > > ?> -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.general (#8536) next »