Helma Logo
main list history
previous version  overview  next version

Version 8 by Lehni on 19. March 2006, 04:54

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|http://jroller.com/page/roblambert?entry=thoughts_on_snakes_and_rubies*

A short summary of these efforts:

First there was my trial of creating a Velocity Engine Extension for Helma: *23-11-05|http://helma.org/pipermail/helma-dev/2005-November/002358.html*. 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|http://www.scratchdisk.com/Random+Notes/November+2005/Helma+Templates/*.

The two extensions are available through CVS: *FreeMarker Extension|http://adele.helma.org/source/viewcvs.cgi/extensions/freemarker/?cvsroot=hop*, *Velocity Extension|http://adele.helma.org/source/viewcvs.cgi/extensions/velocity/?cvsroot=hop*.

And here are the readme files with a brief description of how to install and use the extensions: *FreeMarker README.txt|http://adele.helma.org/source/viewcvs.cgi/extensions/freemarker/README.txt?rev=HEAD&cvsroot=hop&content-type=text/plain*, *Velocity README.txt|http://adele.helma.org/source/viewcvs.cgi/extensions/velocity/README.txt?rev=HEAD&cvsroot=hop&content-type=text/plain*.

The FreeMarker extension is able to call Helma macros through a slightly different syntax: <tt>&lt;@this.macro foo="bar" bla="bla" /&gt;</tt>. As an extension, it also is possible to use nested content in macros: <tt>&lt;@this.nested foo="bar"&gt;Nested text&lt;/@&gt;</tt>. 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.

*Helma 2 Templates - JST*Read more about this template engine here: *JavaScript Template Engine*

     removed
     added