Note: skin/templating features are undergoing redesign for the 0.5 release.
The helma/skin module provides web application developers with a flexible templating framework.
At its simplest, creating and rendering a skin looks like this:
helma> include('helma/skin');
helma> var skin = createSkin('Hello <% name %>!');
helma> skin.render({ name: 'World' });
Hello World!
The part wrapped in <% %> is called macro tag in Helma NG. Macros are replaced at render time
by looking for corresponding properties or functions in the context argument passed to Skin.render().
Helma also provides a number of built-in macros which are described below.
Subskins
A very important feature are subskins, which are named skin fragments that work pretty much like functions work in
JavaScript. A subskin is created using the built-in <% subskin %> tag and ends with the begin of the
next subskin or the skin end.
<% subskin hello %>
Hello <% name %>!</pre>
Use the built-in <% render %> macro to render a subskin with the current context:
<% render hello %>
Provided the skin.render() method is called with context argument
{name: 'Luisa'} the output will be:
Hello Luisa!
You can also bind values to the macro context in the tag:
<% set {name: Julia} render hello %>
Hello Julia!
Loops
The for..in macro gives you an easy way to loop through arrays and other objects that support for-in loops in JavaScript.
<% for name in <% names %> render hello %>
Hello Benni! Hello Emma! Hello Luca! Hello Selma!
Or you can define the objects to loop through using object and array literals in the macro tag:
<% for name in [Gerlinde, Ralph, Thomas] render hello %>
Hello Gerlinde! Hello Ralph! Hello Thomas!
Filters
Finally, filters let you do all kinds of post-processing on the output of a macro.
<% render hello | uppercase %>
HELLO LUISA!
Visit the Helma NG site to learn more about skin rendering.