X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Smarty Math using a Variable (https://forum.x-cart.com/showthread.php?t=36909)

jharwood 01-21-2008 11:38 AM

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

gb2world 01-21-2008 10:36 PM

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>

jharwood 01-21-2008 10:47 PM

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


All times are GMT -8. The time now is 07:09 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.