[PHPTAL] variable variables in phptal?

2012-08-29 Thread GRolf




Is it possible to use variable variables in PHPTal ?

eg I have a PHP array
$phptal-fieldnames = array(array('key'='first_name', 
'description'='First Name'), array('key'='address', 
'description='Address');


and an object
$person= new stdClass();
$person-first_name = 'Joe';
$person-address='His_street 1';
$phptal-person = $person;

and in my template I'd like to use the key of fieldnames in a repeat 
...



div tal:repeat=field fieldnames
${field/description}: ${person/${field/key}}
/div


This doesn't work - but is there an other way to achieve it ?

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal


Re: [PHPTAL] variable variables in phptal?

2012-08-29 Thread Marco Pivetta
Use the ArrayAccess interface and implement your own iterator in your
Person object, no?

http://php.net/manual/en/class.arrayaccess.php

Marco Pivetta

http://twitter.com/Ocramius

http://marco-pivetta.com



On 29 August 2012 15:39, GRolf ger...@pictureparking.com wrote:




 Is it possible to use variable variables in PHPTal ?

 eg I have a PHP array
 $phptal-fieldnames = array(array('key'='first_**name',
 'description'='First Name'), array('key'='address',
 'description='Address');

 and an object
 $person= new stdClass();
 $person-first_name = 'Joe';
 $person-address='His_street 1';
 $phptal-person = $person;

 and in my template I'd like to use the key of fieldnames in a repeat
 ...


 div tal:repeat=field fieldnames
 ${field/description}: ${person/${field/key}}
 /div


 This doesn't work - but is there an other way to achieve it ?

 __**_
 PHPTAL mailing list
 PHPTAL@lists.motion-twin.com
 http://lists.motion-twin.com/**mailman/listinfo/phptalhttp://lists.motion-twin.com/mailman/listinfo/phptal

___
PHPTAL mailing list
PHPTAL@lists.motion-twin.com
http://lists.motion-twin.com/mailman/listinfo/phptal