Re: [PHP Template] Looping and nested sections
[email protected] (Monte Ohrt) Mon, 28 Feb 2000 10:32:17 -0600
| Newsgroups | php.template |
|---|---|
| Organization | ispi |
| Message-ID | <[email protected]> |
Andrei Zmievski wrote:
>
> How should the following situation be handled:
>
> ...
> tmpl_assign("foo", array(1, 2, 3));
> ...
>
> ...
> {{section sec1}}
> ...
> {{ $foo }}
> ...
> {{section sec2}}
> ...
> {{ $foo }}
> ...
> {{/section}}
> {{/section}}
>
> Should only sec1 loop through the values of $foo and sec2 just uses the
> current iteration's value, or should the looping be restarted for sec2?
> It seems that the first solution would be more intuitive. Comments?
>
> -Andrei
>
Something similar was discussed on this topic earlier. I think it would
be handy to be able to identify a variable with its section name,
something like:
{{$sectionname:foo}}
would print the current value of foo for the section. If the section is
omitted and you are within a section block, then the current section is
assumed. With this in mind, you could re-loop every value no matter what
is nested.
example:
{{section sec1}}
...
{{ $foo }}
{{ $sec1:foo }} <!-- prints the same variable as $foo -->
...
{{section sec2}}
...
{{ $foo }}
{{ $sec2:foo }} <!-- prints the same variable as $foo -->
{{ $sec1:foo }} <!-- prints value of outer section foo variable -->
...
{/section}}
{{/section}}