![]() |
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} 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 |
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> |
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.