Re: [PHP Template] Looping and nested sections

From: Date: Mon, 28 Feb 2000 16:32:17 +0000
Subject: Re: [PHP Template] Looping and nested sections
References: 1  Groups: php.template 
Request: Send a blank email to php-template+get-230@lists.php.net to get a copy of this message
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}}

« previous php.template (#230) next »