Hari's CornerHumour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then
PHP templating systems - pros and cons
Software and Technology by
Posted on Sat, Dec 1, 2007 at 10:42 IST (last updated: Wed, Jul 16, 2008 @ 20:38 IST)
- Makes application logic much easier to follow and PHP code much more easier to read.
- Allows you to "skin" your website by using multiple templates. Thus the way your data is displayed is completely in the hands of designers who need no knowledge of PHP code to change the appearance of your application.
- Provides a shorter development cycle. It also allows you to plan exactly how your data should be extracted from source. It makes visualization of your application much easier by providing you quick, alternative views of presenting your data.
- Obviously it allows separation of skills as I mentioned above. A team of developers can be clearly separated into the "programmers" - the ones in charge of the PHP code, and the "designers" - the ones who actually lay out the presentation of the data.
- Using a third-party templating system is a good way to avoid "reinventing" the wheel, thus speeding up development time considerably. It also ensures that you need have no worries about maintaining the template library yourself.
- Processing of templates is an additional overhead you might wish to avoid. In spite of "fast" template parsers around (and Smarty is one of them) they still process text files in the ultimate analysis and any extra file processing increases execution time marginally.
- Sometimes you encounter situations where the application logic can simply not be separated from the content presentation. Yes, this does happen in practical development although finding examples theoritically is tough.
- Template designing can become extremely time-consuming because you are tempted to constantly refine and tweak the content presentation (because it's so easy to). As a result, if you are an individual programmer, you will find your priorities constantly shifting between coding and template development. This can be wearisome, since it involves working with two sets of files and you constantly need to co-ordinate your data fed by the PHP code with the template code.
- Using a templating system in the middle of a project forces you to rewrite or even discard large chunks of your existing PHP code. Even if you strip out all the HTML from PHP, you would need to write a set of "feeder" functions which would allow you to submit the data to the templating system in a format that it can understand. (currently I am forced to consider doing this, since the admin panel of my blogging system is completely written in the old style - PHP intermingled with XHTML).