| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
integer math in a smarty template | |||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() I need to figure out when to restart a loop so I need to do this
<code> {$ItemOrderby = 100} {if $p.orderby gte "100" } {$idiff = $ItemOrderby - $p.orderby } IDIFF = {$idiff} <!-- just printing it out - it's alway blank ... Difference = ITEM {$ItemOrderby} less current {$p.orderby} = {$idiff} {if $idiff gte "100" } </ul> {$ItemOrderby = $p.orderby} {/if} </code> but anyway - it's not doing the subtraction ... I found an old post from 2008 that said use {math} but that it's slow ... and also 2008 was ages ago what is the best way to do this now ? thanks DonnaNJ |
|||||||
#2
|
|||||||||
|
|||||||||
![]() Have you tried {if $p.orderby gte 100 }
(Without the quotes)
__________________
Developing in 4.7.x now (Dipping into v5 - Slowly!) Have used 4.1.x, 4.2.x, 4.4.x, 4.5.x, 4.6.x & 4.7.x Multiple Instances of X-Cart MySQL 5.6.37 CentOS 7.4 Chamber Internet - Lancashire, United Kingdom http://www.chamberelancs.co.uk |
|||||||||
#3
|
|||||||
|
|||||||
![]() That part works
It's just that if the difference is greater than 100 (inother words we're in the 200 series) then I want to close the <ul> and start a new one so in pseudo code if (idiff gt 100) </ul><ul><li> but I diff is coming up blank - not zero - just blank I found this {math assign="amount_to_go" equation="max(0,49-a)" a=$cart.subtotal} so I'm going to try a variation on that |
|||||||
#4
|
|||||||||
|
|||||||||
![]() Again if you trying to perform a comparison with integers then don't put quotes around them.
__________________
Developing in 4.7.x now (Dipping into v5 - Slowly!) Have used 4.1.x, 4.2.x, 4.4.x, 4.5.x, 4.6.x & 4.7.x Multiple Instances of X-Cart MySQL 5.6.37 CentOS 7.4 Chamber Internet - Lancashire, United Kingdom http://www.chamberelancs.co.uk |
|||||||||
#5
|
|||||||
|
|||||||
![]() OK I did that
but i can tell by write statements that it goes into the if block but inside these lines {$idiff = $ItemOrderby - $p.orderby } IDIFF = {$idiff} I try to print using IDIFF= {$idiff} and it prints nothing - not a zero - just blank so it's not doing the math |
|||||||
#6
|
|||||||||
|
|||||||||
![]() Oh, you are trying to assign a variable I believe.
Try just using {$ItemOrderby - $p.orderby} that should print the value you are looking for essentially doing the math and rendering the result. If you need to assign the result to a new variable: {assign var=running_total value=$running_total+$some_array[$row].some_value}
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey XcartGuru X-cart Tutorials | X-cart 5 Tutorials Check out the responsive template for X-cart. |
|||||||||
|
#7
|
|||||||
|
|||||||
![]() I got this to work by doing the math in the assign
{assign var='iprev' value='100'} {foreach from=$pages_menu item=p name=page} {if $p.orderby gte 100 } {assign var='idiff' value=$p.orderby - $iprev} .... {assign var='iprev' value='200'} etc. thanks for pointing me in the right direction ! Donna |
|||||||
|
|||
X-Cart forums © 2001-2020
|