Re:comments on the template engine example document

[email protected] (jm) Thu, 23 Mar 2000 16:38:43 +0000
Newsgroups php.template
Message-ID <[email protected]>
Hi,
  Great that you provided examples and real world usage of your template model.


Now here is my feedback:

First, would it be possible to use
<!-- tplrem here a template comment -->
so that  a WYSIWIG tool for working on the template does get confused about it,
and don't mess the whole layout ?

Same remark does also apply to the {section} keyword.

Another BIG thing is:
  Can section be named ? so more than one can be used in the same template


One use I do of this is conditional code

Real life small example
A page that returns some data from the db.
  3 cases: no data, one single records and a lot of records

What I would usually do is use the same template for the 3 cases,
using 3 sections


<table>
<!-- section name="no_data" -->
<tr><td> No data please try again <td></tr>
<!-- section end -->
<!-- section name="one_record" -->
<tr><td> Welcome {$name} here is your password {$pwd} <td></tr>
<!-- section end -->
<!-- section name="choose_record" -->
<tr><td> There is more than one person fitting your criteria, please choose 
one </td></tr>
<!-- section name="people_record" -->
<tr><td> <a href="whatever.php?id={$id}">{$name}</a></td></tr>
<!-- section end -->
<tr><td> table footnote if you want <td></tr>
<!-- section end -->
</table>

And in the php code, you basically activate one of the three main section.
That is the way we do use templates, and keep logic in the code...
templ("no_data").activate

By default the template engine does clear all section NOT activated.


One stuff that might be useful is some kind of "scope" for the variables,
in order to tell in what loop section it does belongs...

Using multiple sections allow to keep all the logic in the php code, have 
just one file for all the cases and give as much freedom as possible to the 
designers
(and yes, sometimes the designers gave feedback or requirement for the 
design and the template and the logic are changed)

I hope my example was clear...
I found that quite powerful and therefore my rejection of "logic" stuff 
directly in the template. Another thing you might want to consider is that 
not all people are native english speaker and a
{section}
{alternate}
{/section}
is as complicated for them as some php code.

Hopes this helps
--
  jm