Re: [SMARTY] Newbie: probably dumb q about assoc arrays and {section}
| From: | Mark Rogers | Date: | Sun, 04 Jul 2004 12:05:23 +0000 |
| Subject: | Re: [SMARTY] Newbie: probably dumb q about assoc arrays and {section} | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11524@lists.php.net to get a copy of this message | ||
Jeroen,
A few things to look at here.
First, {section} does not work with assoc arrays; it requires your array to
have indexes 0, 1, 2, etc which yours does not. So I would not expect your
first example to work.
However, the solution is to use {foreach}, and your code here looks fine.
I note that you have PHP warnings turned off, which may mean that PHP is
trying to tell you something but you're missing it. I know they're turned
off, because
> $my_items = array(
> ItemCode1 => array (
> ItemName => Name1
> ItemDesc => Desc1 )
> ItemCode2 => array (
> ItemName => Name2
> ItemDesc => Desc2 )
> ...etc.
> );
.. is not valid PHP - all the key and value strings should be quoted:
$my_items = array(
'ItemCode1' => array (
'ItemName' => 'Name1',
'ItemDesc' => 'Desc1' ),
'ItemCode2' => array (
'ItemName' => 'Name2',
'ItemDesc' => 'Desc2' )
...etc.
);
As it stands you're telling PHP to use the constant ItemName (as defined
with the define() function). Since it isn't defined PHP issues a warning and
assumes you mean 'ItemName' instead. (In this example single or double
quotes would work equally well.) Note also the missing commas, which suggest
that the quoted code is not in fact the same code you're trying to use - PHP
throws up more than a warning for that. (Unless of-course you have all
warnings and errors going to a log file which you're not looking at...)
So, in the absence of a visual scan telling me where the problem is, I'd
suggest looking at the error_reporting() function and seeing what that
throws up.
It would help to know: Are simpler Smarty constructs working fine? Do you
get any output at all from the template? Is the template even being found?
Mark Rogers
More Solutions Ltd