When not to use templates

Templates, whilst being very helpful, certainly are not suitable for all environments. If you find that more often than not the pages you create are very specific to a certain task - that is, they'd be hard to generalise into a template-like form - then you definitely fall into the category of programmers who would not get much benefit from switching to templates.

Sometimes it is even the case that switching to templates can create /more/ work for you as a web developer - the act of switching to templates might end up with you spending all your time adding more complexity to your templates, creating various exceptions for specific cases in your sites. We all want to avoid as much programming pain as possible, so if in doubt, try phasing templates in bit by bit.

Another very important reason to avoid using templates is that you lose direct control of the code in quite a large way, at least if you intend to use an off-the-shelf system. Recently, I read a php-dev mailing list thread where IMP for the HORDE code framework was apparently crashing the Zend engine. If I had implemented this and it was crashing on my box, I'd certainly be unhappy - partly because it was crashing, and partly because, as the code is not mine, I would not be able to fix it! Losing control of the situation is always a bad thing, so, if you definitely want to switch to a templating system, at least use one that is stable.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Writing your own >>

Previous chapter: How do they work?

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.