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

Is it possible to do math in Section Loops?

 
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 -> General
View previous topic :: View next topic  
Author Message
FrankinHolland
Smarty Rookie


Joined: 19 Jul 2011
Posts: 14

PostPosted: Fri Dec 09, 2011 1:04 am    Post subject: Is it possible to do math in Section Loops? Reply with quote

Hi. I am trying to do currency conversion on the fly in a Smarty Section Loop. This is what I have (minus irrelevant stuff):

{section name=i loop=$FeaturedProduct}
..
..
<td height="17" class="redmatter">Price: {if $FeaturedProduct[i].dPrice neq ""}{$FeaturedProduct[i].dPrice}{else}{$FeaturedProduct[i].text}{/if}</td>
{/section}

I really want to multiply {$FeaturedProduct[i].dPrice} by a currency converter. Is this possible on the fly by adding something like * 1.564 or a variable? If so what would the syntax be?

Thanks very much.
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Dec 09, 2011 5:57 am    Post subject: Reply with quote

If you are running Smarty 3 you caan use math as you would in PHP like {$FeaturedProduct[i].dPrice * $currency}.

In Smarty 2 just must use the {math} tag.
http://www.smarty.net/docsv2/en/language.function.math.tpl
Back to top
View user's profile Send private message
FrankinHolland
Smarty Rookie


Joined: 19 Jul 2011
Posts: 14

PostPosted: Tue Mar 20, 2012 11:58 pm    Post subject: Thanks! Reply with quote

Thanks again! I somehow missed this reply and found another way but this is very useful.
Back to top
View user's profile Send private message
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 -> General 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