For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > July 2004 > Newbie: probably dumb q about assoc arrays and {section}









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie: probably dumb q about assoc arrays and {section}
Christopher J. Mackie

2004-07-03, 8:56 pm

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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com