title: How to use a dynamic smarty variable in foreach loop
body: <p>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:</p>
  
  <hr>
  
  <pre><code>//file name index.php
  foreach( $subCategories as $s )
  {
      $foo  = intval($s['id_category']);
      $k    = new Category($foo);
      $var1 = "subSubCategories.$foo";
      $var1 = $k-&gt;getSubCategories(1); 
  
      $smarty-&gt;assign(array('foo'.$foo =&gt; $var1)); 
  }
  </code></pre>
  
  <hr>
  
  <pre><code>//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}
          &lt;p&gt;{$subCategories.name}&lt;/p&gt;
      {/foreach}
  {else}
      &lt;p&gt;{l s='test failed'}&lt;/p&gt;
  {/if}
  </code></pre>
  
  <hr>
  
  <p>I've exhausted all of my resources and knowledge and feeling quite helpless at this moment. so plz help me out.</p>
  
  <hr>
  
  <p>I am trying to create dynamic variables (<code>'foo'.$foo</code> i.e. <code>foo1</code>, <code>foo2</code>, and so on) depending on the number of sub-categories. I think m successful up to this point. Now moving on to the tpl file, here I want to access the dynamically created variable (<code>foo2</code>, <code>foo3</code> etc.) using foreach. Now if I am doing this: <code>{assign var=foo value=$foo3}</code> I succeed in fetching the values from this subcategory using the same foreach loop. But when I do this: <code>{assign var=foo value=$foo$catx}</code> (where <code>$catx</code> stores the values for category id) it fails. Please help.</p>