Re: [PHP3] Re: [PHP Template] Re: [PHP3] PHP Template Engine spec revision 0.52

[email protected] (Cliff Rowley) Tue, 21 Mar 2000 23:44:35 +0000 (GMT)
Newsgroups php.template
Message-ID <[email protected]>
> I am providing a solution - you provided it yourself in your example, that
> compared how to implement the template if in PHP code. Use PHP syntax for
> logic, use your templates for presentation.  I won't suggest using 'for'
> loops instead of 'while' loops, which you may consider as constructive
> criticism.  I suggest moving logic outside of the templates engine
> altogether.

I totally agree with that last statement.  I've just been out for a couple
of hours, and I've been thinking on this one.  It does make sense to move
logic out of the idea of templates.  If something depends on logic, it
should be in script itself.  For example, the developer creates some php
code that grabs a list of users.  This (implementation aside) is assigned
a particular name within the template.  The designer takes this and
(again, implementation aside) includes this as defined by the template
engine, and the logic is taken care of, designer unaware; they are merely
piecing together the puzzle.

If there is to be a clear divide between what is script, and what is
design, then it should be a clear divide.  Not just some of the way.  I
hate to keep bringing up sgml, since I dont know an awful lot about it yet
(i.e. I've read about it, but not actually used it yet), but it does seem
to fit in here.  I dont know an awful lot about XML either, or how PHP
uses it, but I am sure it could be used here.

If a clear distinction were made (note that this requires no changes to
php itself, everyone wins here), then at most a designer (or at least the
design part of a project) would only need to use tags, fields, and
template references.  With a combination of xml/sgml, html and php, the
following is quite possible:

<html>
...
<body>
This is a test page, here is a list of users
<tmpl class="usertable" type="all" style="normal">
</body>
</html>

This does entail a little extra work at first, but you're not going to
achieve what you want without penalty.

Ok, it's simplified a lot, but you get the general idea.  This would run
through a parser (possibly a modified sgml/html parser for added
validation) and the template would be expanded.  Given that the example
here is greatly lacking implementation, and the specifics may indeed be
flawed, it's still quite possible that something like this could
work.  This same 'template engine' would not only provide the means to
separate content and script and allow them to be worked separately, but it
could be applied anywhere; not just php.  SGML already provides this in
hundreds of other areas across the scope from programming languages to
documentation.  What's wrong with applying it here?  It requires no
changes in the PHP language itself, and it requires no PHP knowledge to be
useable.

Cliff Rowley

- while (!asleep) { code(); }