Overall structure

Templates are in fact programs you write in a language called FTL (for FreeMarker Template Language). This is a quite simple programming language designed for writing templates and nothing else.

A template (= FTL program) is a mix of the following sections:

Let's see a concrete template. I have marked the template's components with colors: text, interpolation, FTL tag, comment. With the [BR]-s I intend to visualize the line breaks.

  <#-- Greet the user with his/her name -->[BR]
  <h1>Welcome ${user}!</h1>[BR]
  <p>We have these animals:[BR]
  <#list animals as being>[BR]
    <li>${being.name} for ${being.price} Euros[BR]

FTL distinguishes upper case and lower case letters. So list is good directive name, while List is not. Similarly ${name} is not the same as ${Name} or ${NAME}

It is important to realize that interpolations can be used in text (and in string literal expressions; see later) only.

An FTL tag can't be inside another FTL tag nor inside an interpolation. For example this is WRONG: <#if <#include 'foo'>='bar'>...</#if>

Comments can be placed inside FTL tags and interpolations. For example:

<h1>Welcome ${user <#-- The name of user -->}!</h1>[BR]
<p>We have these animals:[BR]
<#list <#-- some comment... --> animals as <#-- again... --> being>[BR]


For those of you who have tried the above examples: You may notice that some of spaces, tabs and line breaks are missing from the template output, even though we said that text is printed as is. Don't bother with it now. This is because the feature called ''white-space stripping'' is turned on, and that automatically removes some superfluous spaces, tabs and line breaks. This will be explained later.

FreeMarker Manual -- For FreeMarker 2.3.20
HTML generated: 2013-06-27 20:54:33 GMT
Edited with XMLMind XML Editor