accessing arbitrary element of an array within template

From: Date: Thu, 28 Feb 2002 15:06:34 +0000
Subject: accessing arbitrary element of an array within template
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-2896@lists.php.net to get a copy of this message
Hi, I'd like to use such an expression in templates what would be $array[$index] in PHP. Consider the following situation: <?php include('Smarty.class.php'); $smarty =& new Smarty; $smarty->assign('array', array('1st' => 'foo', '2nd' => 'bar')); $smarty->assign('index', get_index()); $smarty->display('array.tpl'); ?> I assign two template variables one is an associative array, the other is treated as an index to this array. The array.tpl is the following: {$array[$index]} {* or how? *} As you can realize, I'd like to access the element of $array indicated by an other template variable: $index. I work around the problem with registering a simple variable modifier (index) and change the expression in my template as follows: {$array|@index:$index} Can I do this somehow more elegantly? Thanks a lot, Papp Gyozo - pgerzson@freestart.hu

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