Conducting a small experiment. Been wondering “Just how many template engines does PHP have?”. My guess is there’s probably at least 50 Open Source template engines out there but was hoping for a more precise number. The reason why is get a feel for how many times we’ve re-invented this wheel.
So if I can beg a momemt of time, please add any template engines you know of to this list. They don’t have to be stand alone projects - phpBB for example has it’s own template engine so that counts as one. The main thing is identifying unique template engines.
Not a bad project as it stands at the moment although for more features there needs to be more development; although it’d do it’s job if all you need is basic non complex functionality ?
Think I have to omit that one as it’s now PEAR::HTML_Template_PHPLib unless I’m mistaken. Also the project formerly known as Simple Template (or something like that is now known as PEAR::HTML_Template_Xipe
how about the PHP XSLT extension?
(or the transform capability from libXML2 in the upcoming version of the domdoc extension)
IMO, everything else is a waste of time.
btw. hello everyone. I’ve just dicovered sitepoint (from phpPatterns.com and I’ve been reading posts since midnight (now 2:15am :-))
some good meaty discussions here - my kinda place
Welcome to SitePoint Tezza - You’ll find this forum will be a life saver at times I know it has helped me many a time.
HarryF - DOM ? Proberly would be better to describe this as a form of templating yes ? Your article on DOM Widget’s for example would be a good place to begin.
Welcome as well Tezza - sorry - was mid train of thought.
HarryF - DOM ? Proberly would be better to describe this as a form of templating yes ? Your article on DOM Widget’s for example would be a good place to begin.
Does phpHTMLLib count, or does it fall under the DOM “exemption”?
For me that falls under using PHP itself as a template engine (right now). Of course the author could invent a simple template syntax to eliminate the use of PHP but describes the API (which might be nice for designers)
I’m not so sure. it’s a good question. “Template” implies literal content around which dynamic content can be inserted. but what I tend to do is have a "base"class for my application which uses DOM::append_child and DOM::set_attribute methods to set up a “standard content envelope” for the application (before any transformation happens). So I guess I’m incorporating template functionality when I "initialise"a page in my app.
It’s not a templating system as such though. As in, it’s no a system for implementing templates.
XSLT most definately can be thought of as one though. You literally cannot compile an XSLT template against any XML without using the TEMPLATE directive - even though it is possible to declare an XSLT script without a single literal.
I’m not so sure. it’s a good question. “Template” implies literal content around which dynamic content can be inserted. but what I tend to do is have a "base"class for my application which uses DOM::append_child and DOM::set_attribute methods to set up a “standard content envelope” for the application (before any transformation happens). So I guess I’m incorporating template functionality when I "initialise"a page in my app.
Interesting. Like the definition.
My attempt at this is described here although DOM has to get alot more stable (and have a settled API) before I start using something like that in anger.
<h1>Powered by <phptag id="PHP" /> and <phptag id="MySQL" /></h1>
The markers are the <phptag/> elements which, via DOM, I manipulate in memory. It might be better done something like this though;
<h1>Powered by <a id="PHP" /> and <a id="MySQL" /></h1>
Also it’s probably a bad idea to perform the transformation in memory per page request. Better to parse the “template” with DOM then “compile” into a PHP script containing literal HTML plus PHP code. Something like;
<h1>Powered by <?php
$PHP = & new Tag('a',$dataSource);
echo $php->render();
?> and <?php
$MySQL = & new Tag('a',$dataSource);
$MySQL->render();
?></h1>
Selkirk’s been enlightening me: the Template View - Martin Fowler, in Patterns for Enterprise Application Architecture, describes it as;
Template View: renders information into HTML by embedding markers in an HTML page
Looking over the manual at www.php.net on the DOM I noticed that there are a few functions for XSL stylesheets ?
Umm… In the past I’ve used the Sablotron extension and a class and it worked well enough though I found very few Sablotron web hosts and there is the question of benchmarking.
Now I am pondering on the idea that since nearly all web hosts have the DOMXML extension by default has anyone managed to use XSL-T with the DOM extension to the point of production level ?
It’d be an interesting concept to use XSL via the DOM for templating as I see it maybe…
Sablotron and Expat are going away in PHP5, and the library that does DOM XML now will cover SAX and XSLT parsing. You shlould read Harry’s PHP article.