Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

integer math in a smarty template

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 05-08-2014, 06:25 AM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default 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
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
  #2  
Old 05-08-2014, 06:50 AM
  chamberinternet's Avatar 
chamberinternet chamberinternet is offline
 

X-Wizard
  
Join Date: Sep 2005
Location: Lancashire, UK
Posts: 1,471
 

Default Re: integer math in a smarty template

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
Reply With Quote
  #3  
Old 05-08-2014, 06:59 AM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default 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
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
  #4  
Old 05-08-2014, 07:03 AM
  chamberinternet's Avatar 
chamberinternet chamberinternet is offline
 

X-Wizard
  
Join Date: Sep 2005
Location: Lancashire, UK
Posts: 1,471
 

Default Re: integer math in a smarty template

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
Reply With Quote
  #5  
Old 05-08-2014, 07:49 AM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default 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
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
  #6  
Old 05-08-2014, 08:48 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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}
__________________
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.
Reply With Quote

The following user thanks totaltec for this useful post:
qualiteam (05-12-2014)
  #7  
Old 05-09-2014, 08:37 AM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default 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
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:36 PM.

   

 
X-Cart forums © 2001-2020