Manual
TemplAT File Syntax
template
@ template template-name( parameter1, parameter2, ... ) @
template-body
The template tag defines the file as a
template to be parsed by the Templat class. It must be at the start of
every template file. template-name
is the name of this template. This name must be the
same as the name of the file containing this template, without the ".tat" filetype.
Following the name, in parentheses, is an optional comma-delimited list of
parameters for this template.
Following the template tag
is the template-body (the rest of the file), which may contain other tags (ifs, loops, includes, or expressions).
expression
@ expression @
Any tag that does not start with one of TemplAT's keywords will be treated as an expression.
An expression can be a variable name, a class name, or an integer literal. Classes or variables
may futher have method calls or subscripts (for arrays or Lists). Further details are available in
the
expression reference.
if
@ if ( boolean-expression ) @
if-body
[ @ else @
else-body ]
@ end if @
The if and end if tags,
and optional else tag, define a conditional expansion.
The boolean-expression is evaluated; if the result is true,
the if-body is (parsed and) expanded to the output. Otherwise,
the else-body, if it exists, is (parsed and) expanded to the
output. Note that either body (or both) may contain template tags and/or plain text areas.
loop
@ loop variable : count-expression @
loop-body
@ end loop @
The loop and end loop tags
define a repeated expansion. The count-expression is evaluated, and
the loop-body is (parsed and) expanded that many times to the output. If the count is less than or equal to zero, then
the loop-body will not be expanded. Within the loop-body, the
variable may be referenced within any expression in any tag. The
variable will be a Java Integer. It will hold the value
zero on the first iteration of the loop, one on the next iteration, etc., up to count minus 1 on the final interation.
include
@ include template-path( argument1, argument2, ... ) @
The include tag parses and expands
another template file.
template-path is the (optional path and) name
of the template to be included. The path is interpreted relative to the including template. The
file name of the included template will be the specified name followed by ".tat" filetype. Following
the template-path, within parentheses, you must specify
the arguments required by the included template. These
arguments will be bound to the
parameters defined
by the included template when it is parsed.
text
Areas of the template that are not within any tag will be passed through verbatim to the output.
The one exception is that text cannot contain an at-sign by itself (because an at-sign defines the
start of a tag). Use two at-signs in a row ("@@") in text to indicate a single at-sign in the rendered output.
For example, "john@@example.com" in text within a template would be rendered as "john@example.com" in the
output. However, "john@example.com" in the text would result in a syntax error at render-time.
TemplAT API
Parsing templates is accomplished by the developer writing a Java application (or servlet) and
using the TemplAT API. The TemplAT API is very simple and straightforward, consisting of basically one
class and one method.
The class to use is:
net.sourceforge.templat.Templat
Create an instance of this class, and pass the template's URL to the constructor:
Templat(URL template)
To actually render the template, call the render method:
void render(Appendable result, Object... arguments)