Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Math error

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
pimentel
Smarty n00b


Joined: 25 Nov 2003
Posts: 1

PostPosted: Tue Nov 25, 2003 6:45 pm    Post subject: Math error Reply with quote

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
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Nov 26, 2003 3:26 am    Post subject: Re: Math error Reply with quote

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
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Wed Nov 26, 2003 8:24 am    Post subject: Re: Math error Reply with quote

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 Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP