Re: [PHP3] template engine example document

[email protected] (Andrei Zmievski) Sat, 25 Mar 2000 10:51:29 -0600
Newsgroups php.template
Message-ID <[email protected]>
Hi, Nick.

> I didn't like the difference between $ and @ though, they could be the
> same
> thing really, like:
> {section}
>     <td>$articleTitle</td>
>     <td>$articleDate</td>
> {/section}
> 
> How would it be differently used.

This is how we tried to do it originally. One of the problems with this
approach is that the engine would need to detect at run-time which
variables have multiple values so that it knows that it needs to loop
through them instead of simply printing out the value. Anything done at
run-time is slower, of course. Another reason we thought @ would be nice
is because it's visually clear which variables have multiple values and
are being looped through (@ looks like a loop).

> There is one thing I would like shown to me though.  If I want to skip
> tags
> when a value is empty, how would this be.  Is this the only way:
> {if $value}
>     $value<br>
> {/if}
> 
> would be nicer to link the tag to the var somehow, like:
> {$value{<br>}}
> but maybe some better syntax.

If it's a looping variable, you can do this:

{section}@value<br>{/section}

because sections automatically collapse if variables inside them have no
values.

> Also how would a blank value be changed to &nbsp; for example, can you
> define defaults for a value somehow, e.g.:
> {$value default="&nbsp;"}

Once again, you'd probably want to do this only for looping variables,
when they run out of values. For single value variables, it wouldn't be
too useful. Unless you have a good example?

-Andrei
* Use the source, Luke. *