How to use a dynamic smarty variable in foreach loop
Posted
by
P Kumar
on Stack Overflow
See other posts from Stack Overflow
or by P Kumar
Published on 2011-01-17T09:28:44Z
Indexed on
2011/01/17
9:53 UTC
Read the original article
Hit count: 260
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.
© Stack Overflow or respective owner