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

Using integers within Smarty

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 10-15-2008, 06:42 AM
 
DavyMac DavyMac is offline
 

eXpert
  
Join Date: Apr 2007
Location: Poole, UK
Posts: 333
 

Default Using integers within Smarty

How do you create an integer variable, assign it a value, compare the value of the variable with an integer and then increment the variable using Smarty?

I've tried to do this but always manage to print out the arithmatic, e.g.

I want to count the number of lines of HTML that I create so I have a variable $lines which I set to 0, $lines=0.

For each line of HTML created I increment the variable, $lines=$lines+1.

I then test to see if 12 or more lines of HTML have been created, {if $lines >= 12}

When I do this the resultant HTML shows the variable being incremented, e.g. line 4 has "0+1+1+1+1"

I don't want to output numbers I just want to use them to control my output.
__________________
X-Cart GOLD Plus v4.5.4
CDSEO Pro
ewdhosting Dedicated Server
Dedicated SSL
Stone Edge OM
Reply With Quote
  #2  
Old 10-15-2008, 06:58 AM
  Yurij's Avatar 
Yurij Yurij is offline
Banned
 

X-Adept
  
Join Date: Jan 2008
Posts: 486
 

Default Re: Using integers within Smarty

Quote:
Originally Posted by DavyMac
How do you create an integer variable, assign it a value, compare the value of the variable with an integer and then increment the variable using Smarty?

I've tried to do this but always manage to print out the arithmatic, e.g.

I want to count the number of lines of HTML that I create so I have a variable $lines which I set to 0, $lines=0.

For each line of HTML created I increment the variable, $lines=$lines+1.

I then test to see if 12 or more lines of HTML have been created, {if $lines >= 12}

When I do this the resultant HTML shows the variable being incremented, e.g. line 4 has "0+1+1+1+1"

I don't want to output numbers I just want to use them to control my output.

Create value:
PHP Code:
{assign var="test" value="0"

Increment:
PHP Code:
{math equation="x + 1" x=$test assign="test"

Compare:
PHP Code:
{if $test gte 12}
   
ok
{/if} 
Reply With Quote
  #3  
Old 10-15-2008, 07:34 AM
 
DavyMac DavyMac is offline
 

eXpert
  
Join Date: Apr 2007
Location: Poole, UK
Posts: 333
 

Default Re: Using integers within Smarty

Thanks Yurij,

That works a treat, and I would never have guessed the syntax for incrementing.
__________________
X-Cart GOLD Plus v4.5.4
CDSEO Pro
ewdhosting Dedicated Server
Dedicated SSL
Stone Edge OM
Reply With Quote
  #4  
Old 10-15-2008, 07:35 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Re: Using integers within Smarty

Don't use math - its slow. Just use assign:
PHP Code:
{assign var="test" value="`$test+1`"
Depending on what exactly you are trying to do you also might look at the Smarty cycle function.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 05:42 AM.

   

 
X-Cart forums © 2001-2020