Another nested array prob
| From: | graeme at i7 dot com dot au | Date: | Mon, 26 Feb 2001 07:05:39 +0000 |
| Subject: | Another nested array prob | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-225@lists.php.net to get a copy of this message | ||
I'm tinkering with Smarty for some templating work. I've got a hellish page
to enter as templates which involves (for now) some nasty array work. Maybe
I'm having a brain freeze day :)
If I have an array thus
$level2["NEWS"] = array("jsname"=>"news", "spacing"=>
27 );
$level2["FINANCE"] = array("jsname"=>"finance",
"spacing"=>27 );
$level2["SPORT"] = array("jsname"=>"sport",
"spacing"=>27 )
Is it possible to access the name of the key? e.g. NAME
In the code:
$smarty->assign("tpl_level2", $level2);
And in the template:
{section name="lvl2" loop=$tpl_level2}
{$lvl2/tpl_level2.jsname}
{/section}
I'm guessing this is not possible so some slight restructuring of the array
is necessary. It's not important, just curious :)
The bigger problem is accessing nested arrays. (apologies for nesting etc)
$level3 =
array(
array(
"name" => "NEWS",
"div" => "lvl3news",
"links" => array(
array( "text" => "News One", "url" =>
"http://www.newsone.com/", "target"
=> "_top"),
array( "text" => "Nines Two", "url"
=>
"http://www.newstwo.com/", "target"
=> "_top")
)
),
array(
"name" => "SPORT",
"div" => "lvl3news",
"links" => array(
array( "text" => "NineMSN", "url" =>
"http://www.ninemsn.com.au/",
"target" => "_top"),
array( "text" => "NineMSN", "url" =>
"http://www.ninemsn.com.au/",
"target" => "_top")
)
)
);
$smarty->assign("tpl_level3",$level3)
In the template:
{section name="lvl3" loop=$tpl_level3}
{$lvl3/tpl_level3.name}<BR>
{$lvl3/tpl_level3.div}<BR>
{/section}
I've tried every conceivable combo to access the array inside 'links' but
to no avail. Can someone give me a clue? :)
I checked out the earlier post on this but I wasn't able to clean much from
it.
Cheers,
Graee