Re: accessing arbitrary element of an array within template

From: Date: Fri, 01 Mar 2002 16:19:34 +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-2910@lists.php.net to get a copy of this message
Isnt. getarray is a function: function smarty_mod_getarray($someindex,$somearray) { return $somearray[$someindex]; } 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 2:14 PM Subject: [smarty] Re: accessing arbitrary element of an array within template 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 | --- 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/

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