How to use a dynamic smarty variable in foreach loop
- by P Kumar
Hi,
Can anyone tell me how to use dynamic variables in smarty foreach loop. I am trying to create a module in prestashop and m very close to get it done.
here's my code:
//file name index.php
foreach($subCategories as $s)
{
$foo = intval($s['id_category']);
$k = new Category($foo);
$var1 = "subSubCategories.$foo";
$var1 = $k-getSubCategories(1);
$smarty-assign(array('foo'.$foo = $var1));
}
//file name:index.tpl
{assign var=foo value=$foo$cat}
//where $cat is a variable that counts the number of categories
{if isset($foo) AND $foo}
{foreach from=$foo item=subCategories name=homesubCategories}
<p>{$subCategories.name}</p>
{/foreach}
{else}
<p>{l s='test failed'}</p>
{/if}
I've exhausted all of my resources and knowledge and feeling quite helpless at this moment. so plz help me out.