Re: [SMARTY] assigning zero

From: Date: Fri, 11 Oct 2002 06:57:05 +0000
Subject: Re: [SMARTY] assigning zero
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6115@lists.php.net to get a copy of this message
Normally I use the following syntax to check for empty values if (strval($myvar) == "") { ... } This works in all cases for my belongs. Not sure what side effects this may have. Perhaps we could replace the modifier to something like this: function smarty_modifier_default($string, $default = '') { if (empty($string) && strval($string) == "") return $default; else return $string; } Have fun, André "Josh Johnson" <mailing_lists@allusiveimage.com> schrieb im Newsbeitrag news:006301c2705e$7cbcf430$8b00a8c0@manpa... > That's php, not smarty :) > > The default modifier is 6 lines of code: > > function smarty_modifier_default($string, $default = '') > { > if (empty($string)) > return $default; > else > return $string; > } > > the function empty() [http://www.php.net/manual/en/function.empty.php] > will evaluate to true if a value is 0. I'm sure if somebody really > wanted to they could re-write the function to take type literally (i.e. > don't print the default regardless if the value was 0 or null or > whatever, try to print a representation of that value), but the again, > why would they do something like that? :) > > -- Josh > > -----Original Message----- > From: webmaster@rpgateway.de [mailto:webmaster@rpgateway.de] > Sent: Thursday, October 10, 2002 5:17 AM > To: Christian@aqs-carcontrol.be; St@366ber.ws-pieter; Pieter Van Winckel > Cc: smarty > Subject: Re: [SMARTY] assigning zero > > I found the problem. The problem was that I defined the variable in the > template like this : > > {$content|default:""} > > i deleted the default-part and now it is working. It seems that smarty > interprets 0 as no value, so that the default-value (nothing) jumped in. > Good to know for future use i guess. > > cu, Christian > > > ----- Original Message ----- > From: "Pieter Van Winckel" <pvw@aqs-carcontrol.be> > To: <Christian@aqs-carcontrol.be>; <St@366ber.ws-pieter> > Cc: "smarty" <smarty-general@lists.php.net> > Sent: Thursday, October 10, 2002 8:45 AM > Subject: Re: [SMARTY] assigning zero > > > > On Wed, Oct 09, 2002 at 09:34:02PM +0200, Christian St?ber wrote: > > > Hi, > > > > > > I want to assign the value 0 (zero) to my template but it just does > not > > > print anything. I`m using Smarty 2.3.0. Any ideas? > > > > > > Thanks, Christian > > > > > More info please like the assing, because normally you just > > say $smarty->assign('var',0); > > > > > > > > > -- > > > Smarty General Mailing List (http://smarty.php.net/) > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > -- > > Smarty General Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

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