variable as key in arrays

From: Date: Tue, 11 Jan 2005 11:33:02 +0000
Subject: variable as key in arrays
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12143@lists.php.net to get a copy of this message
Hi, can't find a solution for the following problem: I'm building a "universal" template for several lists. For this, I use an array, specifying the column-types ($aDf.felder), and an second array for the data ($aData). Depending on the column-Type, another row in the template is used, that makes it easy for the HTML-Coder to make the design. And to change the output of a field with a new type of content. So, there is a foreach, looping the Array $aDf.felder, deciding via if/else, which field-type we have (which <td>-Row to select), and several Rows for the data. Because i don't know the keys of the data-array while writing the template, the keys have to be defined by variable. In PHP I would write: $data.$$key How to do this in smarty? For understanding, here the codepart of the template, without the table-header, comments in german (sorry): {* Inhalt *} {foreach name=inhalt from=$aData item=data} <tr valign="top" class="bestinhaltweiss"> {foreach from=$aDf.felder key=key item=feld} {if $feld.typ eq 'link' and $feld.ignore eq 'false'} {* Zeile mit Link *} <td width="9%"><a href="{$data.ziel}">{$data.linktext}</a></td> {elseif $feld.typ eq 'link' and $feld.ignore eq 'true'} {* link ohne spez. Beschriftung *} <td width="9%"><a href="{$data.ziel}">{$feld.linktext}</a></td> {else} <td nowrap>{$data.$$feld.feld}</td> {* das tut so nicht, oder? *} {/if} {/foreach} </tr> {/foreach} any ideas? Or am i wrong in doing it this way? thx for help Tobias -- Tobias Daur :: daur@gmx.de

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