dynamic name variable

Author Message

Romain Bremaud

Wednesday 03 November 2010 8:52:11 am

Hello everybody.

I have a little problem. I would like to have dynamic name variable.

I know to do that in php :

${'example'.$i}

But I don't know how to do that in eZ template. It is possible?

Thanks in advance.

Romain Bremaud
Les clefs du net

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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.