Re: [SMARTY] Variable variables in templates?
| From: | messju mohr | Date: | Mon, 24 Mar 2003 10:54:40 +0000 |
| Subject: | Re: [SMARTY] Variable variables in templates? | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-8858@lists.php.net to get a copy of this message | ||
On Mon, Mar 24, 2003 at 11:46:34AM +0100, philippe.morange@ca-indosuez.com wrote:
> >> 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?
use a 2-dimensional-array "list" for sth. like that and do
{foreach from=$list.$i item=list_item}...
> >> I tried different things with "assign" and "eval" but nothing
> >> works :(
> >>
> >> Bye...
> >> Nagger