PHP vs template engine [closed]

I'm currently having a discussion about the choice between PHP as a template engine versus a template engine on top of PHP.

What is your choice, and why?

I say why use another template engine when PHP is a template engine itself.


For template engines:

  1. Added security for end-user customization. Themes in pure PHP have unconstrained ability to cause harm to a user and their installation. Thus a template engine removes that risk, if it is a good one.
  2. Ease of use for non-programmers, such as graphic artists or web designers.

For plain-php:

  1. The speed of pure PHP cannot be matched by any template engine built atop it.
  2. The full power of PHP is available to the output, and not just an interpreted or filtered portion.

I prefer PHP itself if at all possible. And most folks don't want to hack your software by making a custom theme, so it's easy to take a cursory read and investigate its security. That said, I am the "between guy" who does both templating and programming, and even some graphic arts; my skillset differs from a strict programmer and a strict artist/designer.


I found that when I introduced Smarty, it was fairly straight forward to get web designers to produce HTML with smarty variables. The folks on the programming team now concentrate on more back-end work, that is, the production of the content of the Smarty variables.

This has shortened the development lifecycle, with work being able to be split between more people, and has ultimately led to better designs.


Well, it's just my opinion, but template engines suck. You have to first understand how the template engine is implemented and then learn how to use it. It seems just wasted time, because PHP alone does it best and offers much more flexibility.


The following reasons apply:

  • Separating your application into templates with an engine makes your application less vulnerable to halting code errors
  • Using templates can give you greater flexibility in the future when refactoring because the namespace won't be directly built into the application
  • Using templates encourages (forces) developers to keep business logic and code OUT of the presentation layer.
  • Using templates it is easier to mock up datasets and pass them to a template engine and get a preview of what the site will look like with data