Re: template engine...why???
| From: | rush | Date: | Wed, 30 Apr 2003 14:57:31 +0000 |
| Subject: | Re: template engine...why??? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145783@lists.php.net to get a copy of this message | ||
"Rasmus Lerdorf" <rasmus@lerdorf.com> wrote in message
news:Pine.WNT.4.53.0304300634430.728@DELL...
> Don't discount the fact that PHP was originally a templating system, and
> it still is! My contention is that any general-purpose templating system
> will eventually evolve to become PHP because you simply cannot solve all
> templating problems without some presentation-level logic and once you add
> the first signs of template-level logic, you will eventually turn into
> PHP.
The situation you are describing is indeed present in number of templateing
engines, and I usually call it template polution, but I do not agree that is
inherently unavoidable in every php template system.
The approach I have taken with TemplateTamer is that whole logic is coded in
php files (and in php language of course), and templates contain only html,
and markers for beginning of the template, end, and ariable place holder. I
think this approach is a mix of best things, php is used for programming
logic and there is no need to create yet another language to be used inside
the templates, and templates remain very simple.
There is of course question how are the templates controled from the php.
Generaly for each page, you should implement a class that defines getData()
function. Result of this function should be an array that defines which
templates from the possible set should appear, which ones to repeat, and
what values variables will have. Like in the following which 'turns-on'
templates HELLOHEADER, HELLOBODY and fills the variables MYNAME and GREETING
in the later:
array(
'HELLOHEADER' => array( ),
'HELLOBODY =>array(
'MYNAME' => 'pero',
'GREETING' => 'Zdravo svijete'
)
)
In a way, one can think of it as providing the data, which will be
"rendered" by template engine. In a way it also resembles how things are
processed in xml+xslt combination, where you as a programmer provide xml
tree that will get rendered. But this is where similarity ends since in
xml+xslt combination you as a programmer are responsible to prepare xslt
files that do the transformation and run the whole process by appropriate
calls to xml libraries, while with TemplateTamer equivalent work is all done
by the framework, and even more important there are no xslt files to
prepare.
For closing, I can also agree that one can view a php as an templateing
system in it self but I see it as a different kind, or operating on
different level, which does not necessary preclude usage or diminish value
of additional template systems that complement it.
rush
--
http://www.templatetamer.com/