Directives

You use FTL tags to refer to directives. In the example you use the list directive. Syntactically you do it with two tags: <#list animals as being> and </#list>.

There are three type of FTL tags:

I assume you understand this without further explanation, since it is similar to HTML syntax. The format of the parameters depends on the directivename. The empty directive tag is equivalent to a start-tag plus an end-tag where there is nothing between them. If the directive doesn't support nested content (content between the start-tag and the end-tag), you must use the start-tag with no end-tag or an empty directive tag.

In fact there are two types of directives: predefined directives and user-defined directives. For user-defined directives you use @ instead of #, for example <@mydirective>...</@mydirective>. But user-defined directives is an advanced topic that will be discussed later.

FTL tags, like HTML tags, must be properly nested. So the code below is wrong, as the if directive is both inside and outside of the nested content of the list directive:

<ul>
<#list animals as being>
  <li>${being.name} for ${being.price} Euros
  <#if use = "Big Joe">
     (except for you)
</#list>
</#if> <#-- WRONG! -->
</ul>  

If you try to use non-existing directive (e.g. you mistype the directive name), FreeMarker will decline to use the template and produce an error message.

FreeMarker ignores superfluous white-space inside FTL tags. So you can write this:

<#list[BR]
  animals       as[BR]
     being[BR]
>[BR]
${being.name} for ${being.price} Euros[BR]
</#list    >  

You may not, however, insert white-space between the < or </ and the directive name.

The complete list and description of all directives can be found in the Directive Reference; however I recommend that you read the chapter about expressions first.

Note

FreeMarker can be configured so that it also understands predefined directives without # (like <if user = "Big Joe">...</if>). However we don't recommend the usage of this mode. For more information read: Reference/Deprecated FTL constructs/Old FTL syntax


Page generated: 2004-06-15 22:17:59 GMT FreeMarker Manual -- For FreeMarker 2.3