Re: [PHP Template] Request for comments - nested sections/looping/padding

[email protected] (Monte Ohrt) Wed, 01 Mar 2000 14:00:20 -0600
Newsgroups php.template
Organization ispi
Message-ID <[email protected]>
It looks as if we are running into a problem of ambiguity. If we are
inside
of a section, how do you know what variables to loop, and what not to
loop?

For example:

{{section sec1}}

	{{$SCRIPT_NAME}}<br>
	{{$title}}<br>
	{{$description}}

{{/section}}


$SCRIPT_NAME is a single value, while $title and $descriptions are
arrays of values.
By default, $SCRIPT_NAME would print only in the first loop.
What if we wanted $SCRIPT_NAME to be printed on every iteration?

Here are some possible solutions:

{{section sec1 default="" pad=last}}

	{{$SCRIPT_NAME}}<br>
	{{$title}}<br>
	{{$description}}

{{/section}}

This means that variables within the section are repeated with the last
value once the array is out of variables.

{{section sec1}}

	{{$SCRIPT_NAME loop=no}}<br>
	{{$title}}<br>
	{{$description}}

{{/section}}


Here we have finer control by putting an attribute on a variable itself,
telling the template engine that this variable should not be looped, but
just print its first value on each iteration.

I would vote that putting attributes on the variables themselves sounds
like the most desirable method. Keep in mind, we want to keep this as
easy as possible for designers, so default behaviors and values are
going to be critical.

So, by default the behavior will be:

* single value variables should repeat its value for each iteration, but
can be overridden with a variable attribute (loop=yes)
* arrays should loop through the values, and have a blank value once the
array is depleted, this can be overridden with a variable attribute
(loop=no), or section attribute (default="" pad=none)

Another crazy idea is to explicitly give the variables to be looped:

{{section sec1 vars="title,description"}}

	{{$SCRIPT_NAME}}<br>
	{{$title}}<br>
	{{$description}}

{{/section}}

and by default, loop them all if attribute vars is not given. Or loop
them all but single value vars. :-)

Monte

Andrei Zmievski wrote:
> 
> On Wed, 01 Mar 2000, Monte Ohrt wrote:
> > > {{ if #LAST }}
> > >
> > > Makes no sense.
> >
> > Of course it doesn't. That's like saying {{ if #EVEN }} outside
> > of a section.
> 
> Sure, but at least #EVEN is a variable, it has a boolean value, 0 or 1.
> #LAST is not a variable, what is its value?
>