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

Smarty Math using a Variable

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 01-21-2008, 11:38 AM
 
jharwood jharwood is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 67
 

Default Smarty Math using a Variable

I am trying to customize the layout for the way the subcategories.tpl template displays subcategories and have run into a problem using a variable in a math equation. The variable is the "count" of the number of subcategories and it can easily be made to correctly show the correct number on the page (just to know it does carry the correct number) with:

Code:
{count value=$subcategories print="Y"}

I am trying to use that variable in a math formula to divide 100 by the variable and yield the correct percentage value for table cells based upon how many subcategories there are (never more than 5 in this store, which would be 20%). The following yields the desired end product using a fixed value, "x=2" in this case, in place of the variable.

Code:
{foreach from=$subcategories item=subcat} <TD align="center" valign="bottom" width="{math equation="100 / x" x=2}%" height="220" background="{$subcat.icon_url}">&nbsp;<A href="home.php?cat={ $subcat.categoryid }"><FONT class="CatList" size="4"><B>{ $subcat.category|escape }</B></FONT></A><BR></TD> {/foreach}

All of my attempts to get the variable working in place of the fixed value result in Smarty errors so I am obviously missing the correct syntax to be using. Any ideas?

XCart 4.0.17

Regards,
John
__________________
John Harwood
v3.5.14, v4.0.17, v4.1.8
Reply With Quote
  #2  
Old 01-21-2008, 10:36 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Smarty Math using a Variable

Have you tried to use this, which is the number of elements in the array:
x=$subcategories|@count

You can try and print it first, like you were doing before to see if it has the right value:
<p>count: {$subcategories|@count}</p>
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #3  
Old 01-21-2008, 10:47 PM
 
jharwood jharwood is offline
 

Advanced Member
  
Join Date: Mar 2003
Posts: 67
 

Default Re: Smarty Math using a Variable

Looks like that's the ticket! I know I had tried some variations with the pipe character but must have done it wrong (obviously).

Many Thanks!
John
__________________
John Harwood
v3.5.14, v4.0.17, v4.1.8
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 02:38 PM.

   

 
X-Cart forums © 2001-2020