Re: accessing arbitrary element of an array within template
| From: | Roberto Berto | Date: | Thu, 28 Feb 2002 16:57:29 +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-2897@lists.php.net to get a copy of this message | ||
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
---
You are currently subscribed to smarty as: roberto@berto.net
To unsubscribe send a blank email to $subst('Email.Unsub')
Visit Smarty's homepage at http://www.phpinsider.com/php/code/Smarty/