Five reasons why I don’t like php templating engine

Posted on Category:PHP, MySQL

Recently, I’ve been asked (yet again) by my superiors to use a templating engine on my project. The main reason for this was so that end users can edit the application templates more easily.
Therein lies the first reason:

1. End Users find web templates confusing no matter what template engine they use.
In my experience so far, majority of people that will be editing templates will be web designers that have limited or no knowledge at all about web applications, or ordinary people that don’t know what they are doing. In general, those people should not be allowed to edit templates in the first place.

The second reason is in performance.
2. Performance
No matter how good is the templating engine, it can never be as fast as a direct rendering of a php file. The end.

3. Brackets
I personally prefer to use ordinary brackets () instead of finger-crushing {%%}. For example, have you tried to type this?

{% for key, value in array %}
SOME HTML/tpl code
{% endfor %}

No matter that this way of starting a loop is shorter, it’s still as complicated to write as an ordinary PHP syntax:

<?php foreach($array as $key=>$value){ ?>
//some HTML/PHP code
<?php } ?>

This automatically draws another problem: Most php editors will correctly display the start and end brackets of a loop in standard PHP syntax. When using a template engine, this just does not work and if you have little more complex template, you could have trouble finding the beginning or the end of if, for, or other php function.

4. PHP built-in functions don’t exist in a templating engine unless you define them
A very irritating problem with template engines is that you don’t have majority of standard PHP built-in functions, which means that you have to explain to the templating engine how to use it.

And last, but not least:
5. Lack of documentation
No matter how good the templating engine is, there will always be some poorly documented function that will cost you time and patience, which wouldn’t be a problem if you just used plain PHP :(