Re: [SMARTY] nested section?
| From: | Steve | Date: | Wed, 12 Feb 2003 23:19:54 +0000 |
| Subject: | Re: [SMARTY] nested section? | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-7703@lists.php.net to get a copy of this message | ||
In article <008201c2d243$a4049240$650aa8c0@sweat.d2g.com>,
sweatjejm@mchsi.com (Jason Sweat) wrote:
> Hi Steve,
>
> Off the top of my head, I would say you have to go with foreach
> http://smarty.php.net/manual/en/language.function.foreach.php
> since it is
> not an array indexed from 0.
>
> The template would probably look something like this (untested):
> <table>
> {foreach from=$region_dealer_data item=dealer_list}
> <tr><td>
> {foreach from=$dealer_list item=$dealer}
> <a href="{$dealer.href}">{$dealer.name}</a><br />
> {/foreach}
> </td></tr>
> {/foreach}
> </table>
>
> HTH
>
> Jason
Mmm.. I can't get this to work. I think I wasn't very accurate about the
structure of the array I have to work with. It actually looks more like
this:
$stores =
Array (
"Abc" => Array (
Array (
"href" => "dealer.php?id=18",
"name" => "Alpha Services",
),
Array (
"href" => "dealer.php?id=19",
"name" => "Beta Testers",
),
Array (
"href" => "dealer.php?id=20",
"name" => "Gamma Technology",
),
),
"Bcd" => Array (
Array (
"href" => "dealer.php?id=21",
"name" => "Alpha Tech",
),
Array (
"href" => "dealer.php?id=22",
"name" => "Beta Office",
),
Array (
"href" => "dealer.php?id=23",
"name" => "Gamma Centre",
),
),
"Cde" => Array (
Array (
"href" => "dealer.php?id=24",
"name" => "Alpha Network",
),
Array (
"href" => "dealer.php?id=25",
"name" => "Beta Com",
),
Array (
"href" => "dealer.php?id=26",
"name" => "Gamma Appliances",
),
),
);
The output I'm looking for is like this:
<div>
Abc
Alpha Services
Beta Tester
Gamma Technology
</div>
<div>
Bcd
Alpha Tech
Beta Office
Gamma Centre
</div>
<div>
Cde
Alpha Network
Beta Com
Gamma Appliances
</div>
In PHP I did it like this:
foreach ($stores as $key => $value) {
echo "<div><a
name='anchor_"."$key"."'>"."$key"."</a><br>\n";
foreach( $value as $store) {
echo " <a
href='$store[href]'>$store[name]</a><br>\n";
} echo "</div>\n";
}
No I have to do it in a smarty template... any help appreciated,
Steve
--
steve@conceptualthink.com