View Single Post
  #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