Template Engines

Here’s an interesting article, Template Engines from the author of bTemplate.

In short, the point of template engines should be to separate your business logic from your presentation logic, not separate your PHP code from your HTML code.

That’s the short definition of what a template should do. I think it should also:

  1. Provide application and server security. It could be argued that PHP safe_mode provides a level of security against third-party code.
  2. Make it simple to maintain the template.

In my experience, Smarty syntax is clearer in a html template. Mixing php and html grates on my brain but obviously it’s a subjective matter that many people are happy with.
Nevertheless, if you’re sitting on the fence about using templates, read the above article. See what the author does in his examples, and make up your own mind if they’re useful or not. You might find yourself using Smarty afterwards anyway!

Author: Donncha

Donncha Ó Caoimh is a software developer at Automattic and WordPress plugin developer. He posts photos at In Photos and can also be found on Google+ and Twitter.

Leave a Reply