PHP & Template engines

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1482
Joined: Fri Aug 29, 2003 8:39 pm

PHP & Template engines

Post 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
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
carmofin
Chatterbox
Posts: 26
Joined: Tue Sep 02, 2003 9:41 pm

Post 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... ;)
User avatar
^rooker
Site Admin
Posts: 1482
Joined: Fri Aug 29, 2003 8:39 pm

Code in templates

Post 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!
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply