Re: accessing arbitrary element of an array within template
| From: | Papp Gyozo | Date: | Thu, 28 Feb 2002 17:14:30 +0000 |
| Subject: | Re: accessing arbitrary element of an array within template | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2906@lists.php.net to get a copy of this message | ||
I haven't found getarray() variable modifier, but I assume it's equivalent
with my index().
Thanks, anyway.
----- Original Message -----
From: "Roberto Berto" <roberto@berto.net>
To: <smarty@lists.ispi.net>
Sent: Thursday, February 28, 2002 5:57 PM
Subject: [smarty] Re: accessing arbitrary element of an array within template
| Try {$somearray.$someindex} or {$somearray|@getarray:$someindex}
|
| while getarray is a registred custom function that return the $someindex
| item of the array $somearray
|
|
|
| Atenciosamente,
|
| Roberto Bertó
| 51 32270599
| 51 91169628
| ----- Original Message -----
| From: "Papp Gyozo" <pgerzson@freestart.hu>
| To: <smarty@lists.ispi.net>
| Sent: Thursday, February 28, 2002 12:06 PM
| Subject: [smarty] accessing arbitrary element of an array within template
|
|
| 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
|