Re: [SMARTY] Newbie: probably dumb q about assoc arrays and {section}

From: Date: Sun, 04 Jul 2004 11:06:47 +0000
Subject: Re: [SMARTY] Newbie: probably dumb q about assoc arrays and {section}
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11522@lists.php.net to get a copy of this message
If you change your array to: $my_items = array( array ( Code => Code1 Name => Name1 Desc => Desc1 ) array ( Code => Code2 Name => Name2 Desc => Desc2 ) ); then this should work: {section name=item loop=$items} <input name="{$items[item].Code}" value="{$items[item].Name}">, {$items[item].Desc}<br /> {/section} or with a foreach: {foreach item=item from=$items} <input name="{$item.Code}" value="{$item.Name}">, {$item.Desc}<br /> {/foreach} Jeroen ----- Original Message ----- From: "Christopher J. Mackie" <cjmackie@princeton.edu> To: <smarty-general@lists.php.net> Sent: Sunday, July 04, 2004 1:28 AM Subject: [SMARTY] Newbie: probably dumb q about assoc arrays and {section} I'm missing something in the Help docs for using {section} with associative arrays. I'm sure it's obvious, but I'm not seeing it--any help appreciated. I've got an associative array: $my_items = array( ItemCode1 => array ( ItemName => Name1 ItemDesc => Desc1 ) ItemCode2 => array ( ItemName => Name2 ItemDesc => Desc2 ) ...etc. ); I want to create the following: <input name="ItemCode1" value="Name1">, Desc1<br /> <input name="ItemCode2" value="Name2">, Desc2<br /> etc. If I read the Help docs correctly, it should look like this: --- items.php --- $smarty = new Smarty; ... $smarty->assign( 'items', $my_items ); $smarty->display( 'items.tpl' ); --- .items.tpl --- {section name=item loop=$items} <input name='$items[item]' value='$items[item].ItemName'>, {$items[item].ItemDesc}<br /> {/section} But clearly I *don't* read the Help docs correctly, b/c Smarty prints nothing where any of the array values should be. The array is properly filled--I've triple-checked. I've tried it with and without quotes around the Smarty brackets--no difference. Can anyone see what I am doing wrong? Tx, --CJ -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.smarty.general (#11522) next »