2015-08-09 2 views
2

J'ai cherché mais je n'arrive pas à trouver une solution de travail à mon problème.smarty v3 afficher des éléments de tableau imbriqués dans foreach

Je suis en train de tirer seulement deux éléments d'un tableau: $menu.contents.text et $menu.contents.url

Les tableaux var est menu si vous ne l'avez pas encore deviné. This is what I get lorsque je cours mon code.

Ceci est le code que je l'utilise au moment:

<form name='jump'> 
<select name='menu' onChange='location=document.jump.menu.options[document.jump.menu.selectedIndex].value;' size='1' value='GO'> 
{foreach from=$menu item=result} 
    {if $result.contents} 
     {foreach from=$result.contents item=mc} 
      <option value="{$mc.url}">{$mc.text}</option> 
     {/foreach} 
    {/if} 
{/foreach} 
</select> 
</form> 

C'est le tableau que je suis en train de le saisir de:

array(24) 
{ 
["id"]=> string(2) "91" 
["title"]=> string(11) "Quick Links" 
["name"]=> string(11) "yellowpages" 
["contents"]=> array(1) 
{ 
    [0]=> array(5) 
    { 
     [97]=> array(13) 
     { 
      ["id"]=> string(2) "97" 
      ["menu_id"]=> string(2) "91" 
      ["parent_id"]=> string(1) "0" 
      ["el_id"]=> string(7) "81_6b3a" 
      ["page_name"]=> string(10) "new_ypages" 
      ["level"]=> string(1) "0" 
      ["nofollow"]=> string(1) "0" 
      ["new_window"]=> string(1) "0" 
      ["action"]=> string(4) "read" 
      ["custom_url"]=> string(0) "" 
      ["active"]=> bool(false) 
      ["text"]=> string(13) "New Companies" 
      ["url"]=> string(51) "dealers/new_companies/" 
     } 

     [98]=> array(13) 
     { 
      ["id"]=> string(2) "98" 
      ["menu_id"]=> string(2) "91" 
      ["parent_id"]=> string(1) "0" 
      ["el_id"]=> string(7) "82_cae6" 
      ["page_name"]=> string(10) "top_ypages" 
      ["level"]=> string(1) "0" 
      ["nofollow"]=> string(1) "0" 
      ["new_window"]=> string(1) "0" 
      ["action"]=> string(4) "read" 
      ["custom_url"]=> string(0) "" 
      ["active"]=> bool(false) 
      ["text"]=> string(13) "Top Companies" 
      ["url"]=> string(51) "dealers/top_companies/" 
     } 
    } 
} 
["order"]=> string(1) "1" 
["position"]=> string(4) "left" 
["type"]=> string(4) "menu" 
["extras"]=> string(11) "yellowpages" 
["status"]=> string(6) "active" 
["header"]=> string(1) "0" 
["collapsible"]=> string(1) "1" 
["collapsed"]=> string(1) "0" 
["sticky"]=> string(1) "0" 
["rss"]=> string(0) "" 
["multilingual"]=> string(1) "0" 
["lang"]=> string(2) "en" 
["tpl"]=> string(15) "render-menu.tpl" 
["external"]=> string(1) "0" 
["filename"]=> NULL 
["removable"]=> string(1) "0" 
["subpages"]=> string(0) "" 
["classname"]=> string(0) "" 
["display"]=> bool(true) 
["hidden"]=> int(0) 0 
} 

Quelqu'un voit-il ce que je fais mal?

Répondre

1

Je pense que le premier foreach n'est pas au bon endroit. Essayez ceci:

{if !empty($menu.contents)} 
    {foreach from=$menu.contents item=contentsItem} {* Loop through the contents array *} 
    {foreach from=$contentsItem item=mc} 
     <option value="{$mc.url}">{$mc.text}</option> 
    {/foreach} 
    {/foreach} 
{/if} 
+1

Merci beaucoup, car smart a toujours été source de confusion pour moi. – c0d3x1337