The Dreisam template language

A Dreisam template is a text file. Although the current implementation sends HTML only, in principle the template language can be used to generate any text-based format.

A Dreisam template contains directives which start with {$ and end with $}.

The model is accessed as a tuple with the name m. So if, for example, there is a tuple attribute name, it can be accessed as m.name.

The following directives are supported:

{$ expression $}

The value of the expression. The expression must be of type string. The following characters are escaped: < > & " '

{$= expression $}

The value of the expression. The expression must be of type string. No escaping will occur.

{$%if expression $} text {$%end $}

Will be replaced by text if expression is TRUE, or discarded if expression is FALSE. expression must be of type boolean.

{$%if expression $} text1 {$%else $} text2 {$%end $}

Will be replaced by text1 if expression is TRUE, or by text2 if expression is FALSE. expression must be of type boolean.

{$%loop expression var varname $} text {$%end $}

Will be replaced by text n times with the variable varname set to 0, 1, ... n-1 where n is the value of expression. expression must be of type integer.

Example:

{$%loop length(m.a) var i $}
{$ m.a[i] $}
{$%end $}

If the model has an attribute a which is an array of string, all of its elements will appear in the output, in order.