Page 1 of 1

PHP & Template engines

Posted: Mon Feb 26, 2007 5:20 pm
by ^rooker
I've done some intense reading about different PHP-template engines, and it seems to be mainly a matter of taste. The main idea behind templating is described nicely in a wiki article.

- coders prefer something like smarty, because they can do code in the template, although others consider it big, bloated and slow (and reinvention of the wheel)
- I prefer PEAR::HTML_Template_IT, because there is NO logic in the template, only definition of content blocks.

- One nice approach is to use PHP all the way, but draw a line between business-logic and presentation logic.

- Some are preferring XSLT, since they are well-defined, well-known, widely spread and thus reusable knowledge.



For those who care about speed, here's a site benchmarking some of the most popular template engines

In case you want to stick to Pear-only, here's a quick link-list to different PEAR template packages




...and actually all I wanted to write down was this:
Installing PEAR::HTML_Template_IT package:
(This is mostly for myself in case I need to do this again)

Code: Select all

sudo pear channel-update pear.php.net
sudo pear install HTML_Template_IT

Posted: Mon Mar 05, 2007 7:43 pm
by carmofin
well i would recommend smarty for small applications entirely, i found it great for quick and dirty solutions.
of course you can always argue why the code isnt put into php, but sometimes thats just bothersome.
sure, it would be nice to live in a world where everything has clear design and structure, but in reality we live in a world where everyone has to tunnel everything they do through http because firewalls have become too complex for humanity to handle... ;)

Code in templates

Posted: Tue Mar 06, 2007 12:15 pm
by ^rooker
It really depends on whether the one working with the templates is a designer or a coder.

If it's a non-coder, keep your hands off Smarty! ...otherwise you will end up with more code in your templates than in your actual PHP. Code in templates makes it cumbersome to maintain different "skins", since you will do bugfixing and backporting in your templates, too! (trust me, I've seen it!) ;)

Additionally, it has turned out that "powerful templates" reach the complexity of the programming language below - which is why some clever people have figured out:
Hey! Why not use the underlying interpreter, instead of re-inventing the wheel
So that's why there's a template engine for perl that uses perl, and a template engine for php that uses php, and probably one for python that uses python, and so on...

I'd say that this is the best approach if you want code in your templates. If not: Use Pear's HTML_Template_IT - it's web-designer safe!