PHP Template Engines

Hi, i have been developed a lot of small php websites over the last year using Smarty.

I am now about to start working on a big project for myself and i am wondering if i actually should be using a template engine or not. Can you help me with the following questions

1 - is the use of template engines seen as bad practice and unprofessional
2 - do facebook, twitter, myspace etc use template engines
3 - what is your opinion on smarty
4 - what are the disadvantages of using template engines and or smarty

Thanks in advance for your help…

Here’s my opinion:

1 - No, using a decent template engine is seen as professional. It shows (an attempt at) seperating logic and presentation.
2 - Probably, although I don’t think they use an off-the-shelf templating solution, but their own engines.
3 - Smarty is OK, although I personally find Dwoo and Twig to be cleaner in coding and faster in use.
4 - The biggest disadvantage is that using a template engine causes a little overhead when generating pages. The extra overhead is negligable though, and the advantages (code cleanliness, readability) far outweighs the disadvantages.


Ok cool, thanks… very well put together… the reason i would like to use Smarty as it seems to be the most popular (correct me if i am wrong)

I think for any large project a template engine is a must - even if you use PHP as the template engine. This means you separate your presentation logic from the rest of your code.

Good template engines will provide you with more nice stuff like template inheritance and many convenience functions helping to keep your html readable. I’d say the newest versions of Smarty are pefectly fine and there are others like Twig. The most important thing is not to abuse the template engine - don’t put in them any logic that is not about presentation. Also, I’ve found out that the old Smarty-style of using templates is a big ugly and restricting: first assigning values to the template and then using them like {$var}, etc. I prefer to assign as little as possible to the templates and usually I assign a few objects from which my templates pull data depending on the needs.

What’s more - you should hang on here in this thread a little while - if you are lucky there are a few real Smarty haters in this forum ready to present their opinions :D. I’d say Smarty 3.1 is pretty good and performs quite fast. Just have a look at a few template engines and see which one you like best.

Ok cool, thanks… waiting for the Smarty haters :slight_smile:

I’d say if you have taken the trouble to learn Smarty, stick with it.

The only drawback I see with it is that it can do so many things you can sometimes be tempted to move some of the logic that should maybe be in your page controllers - in which case you could end up with what I call “fat templates”.

I really appreciated the hierarchical way you can build templates up though – and much to my surprise I actually enjoyed working with Smarty for the first time this year.

I agree with what was said above. To add to it, I can tell you that facebook uses XHP, a custom rolled template engine that makes XML a first class citizen of PHP.
I’ve been to talk about it from one of the guys from facebook and it looks pretty cool. Haven’t done anything with it myself though.