X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   integer math in a smarty template (https://forum.x-cart.com/showthread.php?t=69149)

DBK Web Builder 05-08-2014 06:25 AM

integer math in a smarty template
 
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

chamberinternet 05-08-2014 06:50 AM

Re: integer math in a smarty template
 
Have you tried {if $p.orderby gte 100 }
(Without the quotes)

DBK Web Builder 05-08-2014 06:59 AM

Re: integer math in a smarty template
 
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

chamberinternet 05-08-2014 07:03 AM

Re: integer math in a smarty template
 
Again if you trying to perform a comparison with integers then don't put quotes around them.

DBK Web Builder 05-08-2014 07:49 AM

Re: integer math in a smarty template
 
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

totaltec 05-08-2014 08:48 AM

Re: integer math in a smarty template
 
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}

DBK Web Builder 05-09-2014 08:37 AM

Re: integer math in a smarty template
 
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


All times are GMT -8. The time now is 07:31 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.