| Atte André Jensen 2005-02-21, 4:02 pm |
| I'm trying to use indexes in smarty, but can't make it work... I have
the following tow arrays:
$cats = array(
array('name' => 'hans', 'favorite_food_id' => '1'),
array('name' => 'john', 'favorite_food_id' => '2'));
$food = array('1' => array('id' => '1', 'food_name' => 'water'),
'2' => array('id' => '2', 'food_name' => 'bread'));
I would like to get output something like this:
hans loves water
john loves bread
with this template:
{foreach from=$cats item=item}
<p>{$item.name} loves {$food.item.favorite_food_id.food_name}
{/foreach}
The above template doesn't work but this is how it looks in php:
foreach($cats as $cat){
echo $cat['name'].
' loves '.
$food[$cat['favorite_food_id']]['food_na
me'].
'<br>';
}
Can it be done in a smarty template?
Needless to say the above example is a simplified version of a general,
often more complex thing I wish to accomplish.
--
peace, love & harmony
Atte
http://www.atte.dk
|