RSS Feeds

My blog’s templating engine

I first came across a templating engine implementation in phpBB, and the phpBB wiki gives this overview of how it is used.  I felt that the principle of separation of business and presentational logic was a sound implementation goal that helped the maintainability and clarity of the code.  I also liked the concept of preprocessing and caching what is essentially a readable and easily maintainable template into a runtime-efficient cached version, with a lot of processing being hoisted out of the normal page rendering and into the one-off preprocessing.

However, I wasn’t really happy with some aspects of the implementation:

An A+ for the principles, but B- for the implementation, so I googled around for a leaner alternative, and came across a blog post, 19 Promising PHP Template Engines.  I downloaded a few and looked at them and settled on Alan Szlosek’s Vemplator 0.6.1: simple, lean, understandable and quite close to what I wanted.  However, I had some time on my hands and there were some aspects that I kind of missed from the phpBB engine (such as NL support), and I also wanted to improve the runtime efficiency of the compiled template.  So I started refactoring and recoding, and when I was done, I don’t think that there’s a line of Alan’s code left, but the design still owes a lot to him, so I’ve left his name in the credits.

So my engine is currently some 260 lines long and does everything I need.  Anyone is free to take a copy and use it under Alan’s licence terms.  So what is it and how does it work?

Format of Templates

The programming interface