title: Iterating over a multidimensional associative array in Smarty template
body: <p>in a PHP application that uses Smarty I'd like to pass a multidimensional associative array with values describing items and groups of items to a template and display it as a list.</p>
  
  <p>I do something like this in script.php:</p>
  
  <pre><code>$data = array(
      array(
          'type' =&gt; 'group',
          'name' =&gt; 'Group 1',
          'items' =&gt; array(
              array(
                  'type' =&gt; 'group',
                  'name' =&gt; 'Group 2',
                  'items' =&gt; array(
                      array(
                          'type' =&gt; 'item',
                          'name' =&gt; 'Item 1'
                      ),
                      array(
                          'type' =&gt; 'item',
                          'name' =&gt; 'Item 2'
                      )
                  )
              ),
              array(
                  'type' =&gt; 'item',
                  'name' =&gt; 'Item 3'
              )
          )
      ),
      array(
          'type' =&gt; 'item',
          'name' =&gt; 'Item 4'
      )
  );
  $smarty-&gt;assign('data', $data);
  </code></pre>
  
  <p>And I'm using it in main template file:</p>
  
  <pre><code>{include file="display_data.tpl" data="$data"}
  </code></pre>
  
  <p>And in display_data.tpl:</p>
  
  <pre><code>{if $data.type eq 'item'}
      &lt;li&gt;{$data.name} ({$data.type})&lt;/li&gt;
  {elseif $data.type eq 'group'}
      &lt;li&gt;
          {$data.name} ({$data.type})
          {include file="display_data.tpl" data=$data.items}
      &lt;/li&gt;
  {else}
      &lt;ol&gt;
          {foreach from=$data key=k item=i}
              {include file="display_data.tpl" data=$data[$k]}
          {/foreach}
      &lt;/ol&gt;
  {/if}
  </code></pre>
  
  <p>But the effect is only:</p>
  
  <pre><code>&lt;ol&gt;
      &lt;li&gt;Group 1 (group)&lt;/li&gt;
      &lt;li&gt;Item 4 (item)&lt;/li&gt;
  &lt;/ol&gt;
  </code></pre>
  
  <p>In any way I cannot get it iterating over the internal 'items' array. What am I doing wrong?</p>
  
  <p>Thanks in advance for any help.</p>