///PHP as a Templating Language

PHP as a Templating Language

There’s a lot of talk about the use of PHP as a templating language. Some people use Smarty, others use their framework’s/CMS’ inbuilt templating language, while others still use PHP as part of their framework or CMS. Yet, given the high quality templating languages available, why would you be compelled to use PHP for your templates? Here’s why.

PHP as a templating language is a fantastic approach to templating for developers. It’s in a language they’re familiar with, it’s very fast and it just works. Templating engines are much slower, can be confusing at first, and require some time to get used to.

The whole logic/presentation seperation is behind the fundamental concepts of template use, and the debate between native PHP templates – where light PHP code powers the view/template/front-end. The main argument in favour of using a templating engine is that it enforces seperation of behaviour and business logic. Of course, any decent MVC framework does exactly the same.

On the ProDevTips blog, it was suggested that amateur developers, given the chance, would not observe this clean seperation and would start mixing up logic on your view files, creating all sorts of issues. If that’s the case, however, which templating system you use is the last of your worries.

Now, the moment you add a templating language to your application, execution times can literally double, you have to learn another language (as if we didn’t have enough already, what with PHP/HTML/JS/CSS), opcode caching your PHP scripts becomes a whole lot more complicated and you don’t have much to show for it at the end of the day.

Using PHP, on the other hand, allows you to build high performance, scalable applications, gives you templates that you can easily edit when you need to and allows you to add power to your presentation system as and when you need it. Observing clean seperation is simply a matter of practice that doesn’t take too long to get used to.

And besides, if a designer can learn Smarty, learning how to create view files is a piece of cake.

2010-05-25T22:37:11+00:00 February 1st, 2008|PHP|0 Comments

About the Author:

Leave A Comment