PHP, Zend Framework and Other Crazy Stuff
Template Lite: A Sweeter Smarty Alternative
Use the term Template Engine in a PHP forum and the word "Smarty" will inevitably crop up. Smarty is a PHP Template Engine, a library which parses a text file containing Smarty markup and outputs the parsed content as HTML, XML or any other text content you prefer. I like Smarty but, similar to a few PHP libraries, it’s very bloated.
Now I could start throwing the "scalable" buzzword so I’ll immediately limit my post’s scope to concerns on a single server where hardware expansion is not a realistic option. This impacts shared hosts obviously as well as standalone dedicated servers.
Such resources generally have limitations – memory, CPU cycles, I/O vs Database latency, etc. For some people (me!) these are a concern. Faced with resource limits I try to keep my applications lean and mean – small, fast, and adaptable. Unfortunately, Smarty disagrees with my needs. It’s bloated design while packing a mighty punch, uses a chunk of memory and processor time I dislike. Since I also develop open source apps which end up on shared hosts, my concerns are even more justified.
Enter Mark Dickenson. Mark is the developer of a Smarty alternative: Template Lite. Template Lite is not simply another template engine. It’s objective is to maintain Smarty compliance (i.e. it parses Smarty markup) using a redesigned library for minimal memory and CPU cycle consumption. Not happy with just that, Mark has also introduced some non-standard Smarty markup which, simply enough, provides more intuitive methods for traversing arrays, looping, etc. – for example, the SWITCH, FOR and WHILE tags. The results? A Smarty drop-in replacement which is limited to approx. 50% of Smarty‘s usual memory usage and is significantly faster at compiling and displaying templates.
So why use Template Lite? Template Lite is likely not everyone’s cup of tea. It’s an excellent library which is small, readable and surprisingly simple to extend. It’s fast and has approx. 50% of Smarty’s typical memory usage. It’s extendable, and contains additional tags which are more intuitive (to me at least) since they follow programming conventions common to PHP, C++, etc. On the flipside, Template Lite excludes several Smarty features. Use of Template Lite likely depends on how much weight programmers place on these elements. The main one I’ve seen discussed is that Template Lite excludes the "Security" features of Smarty. These place limits on template content and locations which are useful if Templates are editable by untrusted third parties. Technically, this optional behaviour is unnecessary for most purposes (it’s disabled by default in Smarty), but may be essential for some programmers who want to place limits on in-house designers or such. The include_php tag has also been omitted, and error reporting is not very in-depth.
Overall however, I found Template Lite to be a useful addition to the PHP Toolbox. In circumstances where Smarty appears too heavy handed, Template Lite offers a faster alternative. It’s cleaner design and modularity are the icing on the cake. Template Lite 1.90 was the latest version released on 1 September 2006 – if you haven’t already, check it out.
Related posts:
| Print article | This entry was posted by Pádraic Brady on September 20, 2006 at 6:44 pm, and is filed under PHP General. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

Recent Comments