indexing arrays in smarty

From: Date: Mon, 21 Feb 2005 15:53:46 +0000
Subject: indexing arrays in smarty
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12252@lists.php.net to get a copy of this message
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_name']. '<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

« previous php.smarty.general (#12252) next »