Monthly Archives: November 2010

Page Template Frameworks in Java

My new project is very different from the Poker project that I’ve spent the last year doing – it’s all about web sites. The interesting thing about this project is the sheer scale involved – billions of page views a month. Needless to say, this is far a pretty large company where there are big teams working on different aspects. Front end UI guys writing HTML, CSS and JavaScript, Java guys writing services and execution frameworks and DB guys working their magic on the backends.

Where I will be involved is the web tier itself, creating the web application that renders the content and beefs up the site with a whole host of sexy features like A/B testing, SEO, analytics and more. So one of the things I have to do is to come up with an easy way of integrating the HTML produced by the UI guys with the data required to populate it.

Page Template Engines seem the obvious choice with Velocity and Freemarker as stand out candidates. There are some more left field candidates like StringTemplate, Trimpath , Mustache and JPT. JPT is particularly interesting as it is a Java implementation of Zope Page Templates where the template code lives as attributes in the mark up rather than as their own tags.

Consider this example in freemarker where we want to iterate over a list of writers.

<#list writers as writer>
<li>${writer}</li>
</#list>

Here’s the same in JPT

<li tal:repeat=”writer writers”><span tal:content=”writer”>Test content goes here</span>/li>

The benefit is that the JPT fragment is still valid XHTML and you can have placeholder content. This makes the integration between front end devs and web tier guys really simple.

There are a few issues with JPT but it looks interesting enough to have a closer look.