Share » Forums » Developer » dynamic name variable

dynamic name variable

dynamic name variable

Wednesday 03 November 2010 8:52:11 am - 2 replies

Author Message

Christian Rößler

Wednesday 03 November 2010 9:26:39 am

It is somehow possible to access arrays by defining its indexes as variables. The following code is not tested against ez-template and was written straight from mind to keyboard, so make sure to test it.

{def $myarray=array('foo', 'bar', 'hello', 'world')}
{def $index=2}

content from myarray at index {$index} is {$myarray.$index}

I'm not aware of a constuct you stated above which works in the ez template language. Perhaps it's not even a good idea to use such construct as you might throw away memory and cannot purge it. It also leaks those created variables (example1, example2, ...) into other templates.

Perhaps you should consider to use another solution which is more stable. Perhaps use arrays instead?

http://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Template-operators/Arrays

cheers, chris

Hannover, Germany
eZ-Certified http://auth.ez.no/certification/verify/395613

Romain Bremaud

Friday 05 November 2010 1:11:31 am

Thanks for your help Chris. Effectively I managed to make what I wanted with arrays.

Romain Bremaud
Les clefs du net

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu