Re: [PHP Template] Another batch of ideas
[email protected] (Monte Ohrt) Fri, 18 Feb 2000 11:59:21 -0600
| Newsgroups | php.template |
|---|---|
| Organization | ispi |
| Message-ID | <[email protected]> |
Andrei Zmievski wrote:
>
> After reading through Perl's HTML::Template docs I think we can steal
> some ideas from them. Let's talk if these would be useful or not.
>
> - Automatic escaping of variable contents when printing into the output
> optional control through escape=true/false attribute
>
> - Assigning values to vars inside a specific section. I'm not sure if
> this would be useful or not.
>
> - How template path is figured out. The HTML::Template does this:
>
> The file specified can be a full path - beginning with a '/'. If it
> isn't a full path, the path to the enclosing file is tried first. After
> that the path in the environment variable HTML_TEMPLATE_ROOT is tried
> next, if it exists. Next, the "path" new() option is consulted. As a
> final attempt, the filename is passed to open() directly.
>
> Instead of HTML_TEMPLATE_ROOT, we could have an .ini setting. It could
> also check doc_root.
>
> - Having a warning if trying to assign to a variable that is not
> mentioned in the template.
>
> - Having a parameter that specifies whether the parsed template is
> cached.
>
> - Having something like HTML::Template's __FIRST__, __INNER__, __LAST__
> special variables that get activated when we're in first, middle, or
> last iteration of the section loop. Maybe also a number __LOOPNUM__ or
> something that is evaluated to 1, 2, 3, etc.
>
> -Andrei
> * If it's never finished, you can't prove it doesn't work. *
I really like that last idea. But instead of __FIRST__ we should use
another prefix convention, like #VARNAME for variables internal to the
template.
So $varname for environment variables, %varname for config file
variables
and #varname for internal template variables.
Some variable ideas for sections:
#FIRST boolean, true if in the first section loop
#INNER boolean, true if after #FIRST
#LAST boolean, true if in the last section loop
#PREV int, value of previous loop row
#LOOP int, value of current loop row
#NEXT int, value of next loop row
#EVEN boolean, true if current #LOOP value is even
#ODD boolean, true if current #LOOP value is odd
#TOTAL int, value of total number of rows
Also, we may want to define variables within sections, in
the case of nested sections with {#sectionname:varname}
By default, the current section will be assumed.
So an example, we want to color every other row different,
and output the total at the bottom:
<TABLE>
{:section myrows}
<TR>
<TD bgcolor={:if #EVEN}#ff0000{:else}#00eeff{:/if}>
table cell data
</TD>
</TR>
{:/section myrows}
There were {#myrows:TOTAL} rows of data.
</TABLE>