Helma Logo
main list history

Helma 2 Templates - juerg

My efforts for a more flexible template engine can be summarized by the following quote from David Heinemeier Hansson: "Logic in the view is good, BUSINESS logic in the view is BAD" source

A short summary of these efforts:

First there was my trial of creating a Velocity Engine Extension for Helma: 23-11-05. I soon noticed that between FreeMarker and Velocity, FreeMarker seems the more powerfull of the two, and implemented a second extension for this templating engine.
There is a text on my website about it: Helma Template Engines.

The two extensions are available through CVS: FreeMarker Extension, Velocity Extension.

And here are the readme files with a brief description of how to install and use the extensions: FreeMarker README.txt, Velocity README.txt.

The FreeMarker extension is able to call Helma macros through a slightly different syntax: <@this.macro foo="bar" bla="bla" />. As an extension, it also is possible to use nested content in macros: <@this.nested foo="bar">Nested text</@>. The nested contend is passed to the macro as a second argument.

First I was very convinced by FreeMarker and though it was a nice and fitting extension to Helma. But some things I thought were disturbing: It was relatively slow compared to Helma skins, and the builtin modifiers for various datatypes felt very different to Helma's own approach, e.g. format for date types and numbers, and not very JavaScript-like.

There was an unnecessary redundancy between the Rhino parser for JavaScript and FreeMarker's own parser and rendering/runtime engine for templates, which does not seem to be very optimized. On top of that, Rhino's JavaScript values, objects and functions needed wrapper objects for both the Velocity and FreeMarker engine to be able to access from the templates, which was causing additional consumption of resources and slowdowns and felt unnecessary.

The resolution seemed simple: Why not using Rhino as a template engine by parsing templates and turning them into JavaScript code, which then is evaluated and cached as a function object inside the template object. I then put a simple prototype together which worked surprisingly well and performed almost as good as Helma skins, although written in JavaScript.

I am using this third template enigne now in one of my projects, adding and modifying it when I encounter problems or needs for more functionality. It is by no mean finished, but I provide it here anyway because I think it can serve as a nice starting point for quick sketching and trying out of new template approaches for Helma 2.

Read more about this template engine here: JavaScript Template Engine

Links to this page: Gobi Troubles, Helma 2 Templates, JavaScript Template Engine