Re: [SMARTY] Variables and math

From: Date: Fri, 01 Nov 2002 18:58:23 +0000
Subject: Re: [SMARTY] Variables and math
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6305@lists.php.net to get a copy of this message
Yes, this is _one_ solution, but not the one I was hoping for. It should be possible to alter function _parse_var() in the compiler class to allow simple math expressions. It would probably be easier for someone who is involved w/ smarty to do it, but I'll try to fix this myself. Shouldn't be too hard, and I think it's quite useful and I'm not the only one who would use it. Thanks, Victor "Josh Johnson" <mailing_lists@allusiveimage.com> skrev i meddelandet news:004701c281d7$729f7600$8b00a8c0@manpa... > How about this: > > As a plug-in (check the smarty manual and check the syntax... this is > untested): > smarty_function_multiply($params, &$smarty){ > echo $params[factor1]*$params[factor2]; > } > > in your template: > {multiply factor1=$foo factor2=16} > > Or if you need the result, add an assign param... or maybe make it a > modifier function so you can do {assign var=foo_squared > value=$foo|times:2} > -- Josh > > -----Original Message----- > From: Victor [mailto:vboivie@home.se] > Sent: Friday, November 01, 2002 1:44 PM > To: smarty-general@lists.php.net > Subject: [SMARTY] Variables and math > > Hi everybody, > > I want to do this more or less: > > {$foo * 16} > > where foo is a number. Actually my real code is a bit more complex, but > this > should be enough to see what I want to do. The custom function "math" is > not > the correct answer. Anyway, the *16-part is completely ignored by Smarty > and > I don't know what to do. > > Thanks in advance, > Victor > > > > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

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