Re: [SMARTY] Variable variables in templates?
| From: | philippe dot morange at ca-indosuez dot com | Date: | Mon, 24 Mar 2003 10:46:34 +0000 |
| Subject: | Re: [SMARTY] Variable variables in templates? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-8857@lists.php.net to get a copy of this message | ||
>> On Sun, Mar 16, 2003 at 12:38:51AM +0100, Nagger wrote:
>> Hello...
>>
>> Is there a way to handle variable variables in templates?
>>
>> Now I write:
>> {if $i == 1}{$smarty.capture.foo1}
>> {elseif $i == 2}{$smarty.capture.foo2}
>> {elseif $i == 3}{$smarty.capture.foo3}
>> {elseif $i == 4}{$smarty.capture.foo4}
>> {elseif $i == 5}{$smarty.capture.foo5}
>> {elseif $i == 6}{$smarty.capture.foo6}
>> {elseif $i == 7}{$smarty.capture.foo7}
>> {elseif $i == 8}{$smarty.capture.foo8}
>> {/if}
>>
>> But something like that would be nicer:
>> {$smarty.capture.foo$i}
>
> {assign var=foo_i value="foo_$i"}
> {$smarty.capture.$foo_i}
>
> should do.
Well it doesn't for me, as my problem is different: I really need variable variables...
I have assigned a number n of variables from my php files: (n goes from one to infinity).
{$list_1}
Array (121)
0 => Array (3)
id => 1066
name => Beta
contract_name => Data
1 => Array (3)
id => 1
name => Alpha
contract_name => Data International
2 => Array (3)
id => 53
name => Alpha 2
contract_name => Data International
...
{$list_2}
Array (68)
0 => Array (3)
id => 1072
name => Annecy
contract_name => Data
1 => Array (3)
id => 28
name => Bangkok Router 2
contract_name => Data International
2 => Array (3)
id => 44
name => Paris Router
contract_name => Data International
...
In my template I need to use the different lists like this:
{foreach from=$list_$i item=list_item}
<option label="{$list_item.name} ({$list_item.contract_name})"
value="{$list_item.id}">{$list_item.name} ({$list_item.contract_name})</option>
{/foreach}
Where $list_$i refers to $list_1, $list_2, $list_3, etc...
I don't know how many lists I will have, so I have to use variable variables...
What could I do to make this work?
>> I tried different things with "assign" and "eval" but nothing works :(
>>
>> Bye...
>> Nagger
==========================================================
Ce message et ses pièces jointes (le "message") est destiné à l'usage exclusif de
son destinataire.
Si vous recevez ce message par erreur, merci d'en aviser immédiatement l'expéditeur et
de le
détruire ensuite. Le présent message pouvant être altéré à notre insu, Crédit Agricole
Indosuez
ne peut pas être engagé par son contenu. Tous droits réservés.
This message and/or any attachments (the "message") is intended for the sole use of its
adressee.
If you are not the adressee, please immediately notify the sender and then destroy the message. As
this message and/or any attachments may have been altered without our knowledge, its content is
not legally binding on Crédit Agricole Indosuez. All rights reserved.
==========================================================