Re: referencing associative arrays using template variables

From: Date: Wed, 27 Jun 2001 13:15:58 +0000
Subject: Re: referencing associative arrays using template variables
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-1019@lists.php.net to get a copy of this message
On Tue, 26 Jun 2001, Jason Sweat wrote: > I would like to use Smarty to reference the associative array that is the loop variable of an > outer section using the data from the current value of a loop variable of an inner section. My > template looks like this: > > <?xml version="1.0" ?> > <{$BASETAG}> > {section name=data loop=$DATA} > <{$DETAILTAG} id="{%data.index%}"> > {section name=xml loop=$XML} > <{$XML[xml]}>{$DATA[data].$XML[xml]}</{$XML[xml]}> > {/section} > </{$DETAILTAG}> > {/section} > </{$BASETAG}> > > Smarty does not like the {$DATA[data].$XML[xml]} syntax and gives the following error:syntax > error: unknown tag - '$DATA[data].{$XML[%xml.index%]' in > <b>/usr/local/lib/php4/Smarty_Compiler.class.php</b> on line <b>862</b> > > I think I could work around this by restructuring the $DATA array to > have a second dimension that reorders the associative array to be in > the same order as the $XML array in my php script before assigning the > arrays to Smarty, but I would rather dynamically reference the $DATA > array using the $XML array if possible. You know, I don't have an immediate solution, but I do admire the problem. The thing is that if we try to somehow enable using variables for associative array indexing, you have to go all the way and allow full syntax, because you might need to index like this: <{$XML[xml].start}>{$DATA[data].$XML[xml].mydata}</{$XML[xml].end}> that is using $XML[xml].mydata as the string key for $DATA[data]. But then the expression becomes ambiguous: are you indexing $DATA[data].$XML[xml] by 'mydata' key or are you really trying to achieve what you describe. All the little details like this are simply delectable. -Andrei * We reason deeply, when we forcibly feel. *

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