PHP as a templating language
There's been quite a bit of talk, recently, in PHP-land about templates and the ramifications of enforcing a€opurea€¯ PHP scripts by preventing scripts from entering html mode. I'm not quite sure how I feel about this RFC, but it got me thinking about the whole idea of using PHP for templating in modern web apps.
For many years, I was a supporter of using PHP as a templating language to render html. However, I really don't buy into the idea of adding an additional abstraction layer on top of PHP, such as Smarty (and many others). In the past year or so, I've come to the realization that even PHP itself is no longer ideally suited to function as the templating engine of current web applicationsa€‰-a€‰at least not as the primary templating engine for such apps.
The reason for this evolution is simple: modern web apps are no longer fully server-driven.
PHP, as you know, is a server technology. Rendering html on the server side was fine for many years, but times have changed. Apps are becoming more and more API-driven, and JSON is quickly becoming the de facto standard for API envelopes.
Rendering elements to html on the server side, even if transferred through a more dynamic method such as via XHR, really limits what can be done on the display side (where a€odisplay sidea€¯ can mean many things these daysa€‰-a€‰not just browsers).
We try hard to keep the layers our web applications separated through patterns such as Model/View/Controller, but for as long as we've been doing so, we've often put the view bits in the wrong place. This was appropriate for many years, but now it is time to leave the rendering duties up to the layer of your application that is actually performing the view. This is often your browser.
For me, this has become the right way to do things: avoid rendering html exclusively on the server side, and use a techonology that can push data rendering to your user's client.