![]() |
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 |
Re: integer math in a smarty template
Have you tried {if $p.orderby gte 100 }
(Without the quotes) |
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 |
Re: integer math in a smarty template
Again if you trying to perform a comparison with integers then don't put quotes around them.
|
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 |
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} |
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.