Template Engines

Here’s an interesting article, Template Engines from the author of bTemplate.

In short, the point of template engines should be to separate your business logic from your presentation logic, not separate your PHP code from your HTML code.

That’s the short definition of what a template should do. I think it should also:

  1. Provide application and server security. It could be argued that PHP safe_mode provides a level of security against third-party code.
  2. Make it simple to maintain the template.

In my experience, Smarty syntax is clearer in a html template. Mixing php and html grates on my brain but obviously it’s a subjective matter that many people are happy with.
Nevertheless, if you’re sitting on the fence about using templates, read the above article. See what the author does in his examples, and make up your own mind if they’re useful or not. You might find yourself using Smarty afterwards anyway!

b2 plugin support

On the b2 forums there are plenty of hacks and enhancements to b2. While there are guidelines to writing hacks they’re informal, and many hacks rely on changing existing code.
I’m using the Smarty plugins support to provide a consistent and documented way of writing plugins.
I created a simple “googleit” function already. It’s integrated into the post.tpl template of this blog and provides the “Search” link you see below.
Using Smarty plugins is easy. You create your function, call it a predictable name (smarty_function_name() where name is “googleit” for example), put it into a file and drop that file into the plugins directory.

The usual advantage of using Smarty caching applies here too. Once it’s cached the plugin isn’t loaded again until it’s called so you can drop as many plugins as you like into the plugin directory without suffering any speed loss!

Show computed styles bookmarklet

Simon wanted a bookmarklet to examine the css style sheet of any particular html element on a page. Sil created a beautiful bookmarklet that displays the style properties of your page as you move the mouse over them! Wow! Tres nice!
Unfortunately another bookmarklet didn’t work worked strangely in Galeon 1.2.9 (and Moz 1.3). I had to open an close the Javascript console to get it to work I think.