Re: [SMARTY] Newbie: probably dumb q about assoc arrays and {section}
| From: | Jeroen de Jong | Date: | Sun, 04 Jul 2004 11:48:48 +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-11523@lists.php.net to get a copy of this message | ||
or with the same array, and a foreach loop:
{foreach key=key item=item from=$items}
<input name="{$key}" value="{$item.ItemName}">, {$item.ItemDesc}<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