|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
pimentel Smarty n00b
Joined: 25 Nov 2003 Posts: 1
|
Posted: Tue Nov 25, 2003 6:45 pm Post subject: Math error |
|
|
I found an error on Smarty 2.6.0, when using embedded math.
It seems that you must start every expression with a template variable. An example:
[code]
{assign var="counter" value="1"}
{assign var="remainder" value="`3-$counter`"}
{$remainder}
[/code]
outputs `3-1`, instead of the correct result which is 2. If you try
[code]
{assign var="remainder" value="`-$counter+3`"}
[/code]
then you get `-1+3`. The workaround I have used is this ugly expression:
[code]
{assign var="remainder" value="`$counter-$counter-$counter+3`"}
[/code] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Nov 26, 2003 3:26 am Post subject: Re: Math error |
|
|
pimentel wrote: | I found an error on Smarty 2.6.0, when using embedded math.
It seems that you must start every expression with a template variable. An example:
Code: | {assign var="counter" value="1"}
{assign var="remainder" value="`3-$counter`"}
{$remainder}
|
outputs `3-1`, instead of the correct result which is 2. If you try
Code: | {assign var="remainder" value="`-$counter+3`"}
|
then you get `-1+3`. The workaround I have used is this ugly expression:
Code: | {assign var="remainder" value="`$counter-$counter-$counter+3`"}
|
|
Hi pimentel. This is tough, so hopefully I get this right. My understanding of the template math functionality is as follows:
Smarty template math expressions are tightly bound to template variables
As you note, an expression must start with a variable. You also found the most-likely workaround -- start the expression with something like $zero (eg. $zero-2)
No spaces in expressions. Thinking of operators in the same way as modifiers may help with this one.
|
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Nov 26, 2003 8:24 am Post subject: Re: Math error |
|
|
boots wrote: | Complicated math expressions should probably be done with the math plugin for clarity. |
actually "Complicated math expressions" shouldn't be in the template at all |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|