|
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 |
B120 Smarty n00b
Joined: 24 Oct 2014 Posts: 2
|
Posted: Fri Oct 24, 2014 9:19 pm Post subject: Price division and a IF |
|
|
Hi,
I have this function that divides the price by 12:
Code: | {convertPrice price=$product.price/12} |
But i need to add rule:
- If the price is less then 100 the dividing the value must be 6
I still very noob on this, please can someone teach me to add the rule to this function?
Thanks!
Best Regards,
Bruno |
|
Back to top |
|
B120 Smarty n00b
Joined: 24 Oct 2014 Posts: 2
|
Posted: Fri Oct 24, 2014 9:56 pm Post subject: |
|
|
I find it:
Code: | {if $productPrice >= 100}
{convertPrice price=$productPrice/12}
{else}
{convertPrice price=$productPrice/6}
{/if} |
This is the best approach? Can anyone share a definite way?
Best Regards |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Nov 21, 2014 12:17 am Post subject: |
|
|
You should define all conversion logic inside your custom function. |
|
Back to top |
|
n0xor Smarty Rookie
Joined: 04 Dec 2014 Posts: 6
|
Posted: Thu Dec 04, 2014 5:46 pm Post subject: |
|
|
Code: |
{convertPrice price=$productPrice/(($productPrice<100)?6:12)} |
Not tested but this provides much more readability |
|
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
|