When template engines for PHP get in the way

Published on 2013-03-26.

I honestly believe that many people who use template engines in PHP use them because it's the hip thing to do.

Take a car. Inside the car we have the controls to operate the car. We have the steering wheel, the pedals, and the gear stick (whether it's automatic or manual). Now, let's build a shiny box that we can put on top of those controls, an interface. Instead of the steering wheel, the pedals, and the gear stick, we now operate the car using push buttons with lights in them. To some that might look pretty, but what we have done is to add another layer of complexity to the car.

I have never spoken with a web designer who actually found that working with templates was easier than working with PHP.

Why spend time learning some stupid templating language that is just as complicated as the programming language itself? Not only that, but it has to be run on top of PHP, even though PHP basically IS a template engine in and of itself - and a much more efficient one at that!

You might as well spend time learning the real programming language, at least the part you need to use, that will be much more beneficial.

Furthermore, from another perspective, since the template engine adds another layer of complexity on top of your application, you now have multiplied the number of possible bugs.

A template engine for PHP will also always be slower than just using PHP. Because of the template engine PHP now has a ton of parsing and regular expressions to process.

It is perfectly possible to build systems without templates engines and still separate the design aspect from the code simply by using well structured code, you don't need to add the complexity of a template engine.