Synopsis
<#ftl param1=value1 param2=value2 ... paramN=valueN>
Where:
-
param1,param2, ...etc.: Name of the parameter. Not an expression. Allowed parameters are:encoding,strip_whitespace,strip_text, ...etc. See below. -
value1,value2, ...etc.: The value of parameter. This must be a constant expression (astrue, or"ISO-8859-5", or{x:1, y:2}). It can't use variables.
Description
Tells information about the template for FreeMarker and for
other tools, also helps programs to automatically detect if a text
file is an FTL file. This directive, if present, must be the very
first thing in the template. Any white-space before this directive
will be ignored. The old-syntax (#-less) format
of this directive is not supported.
The settings (encoding, white-space stripping, etc.) given here has the highest precedence, that is, they will be used for the template regardless of any FreeMarker configuration settings.
Parameters:
-
encoding: With this you can specify the encoding (charset) of the template in the template file itself. (That is, this will be theencodingsetting of the newly createdTemplate, and not even theencodingparameter toConfiguration.getTemplatecan override it). Note however, that FreeMarker will try to find and interpret theftldirective first with the automatically guessed encoding (which depends on the FreeMarker configuration set by the programmers), and only then realizes if theftldirective dictates something different, and re-read the template with the new encoding. Thus, the template must be valid FTL until the end offtltag with the encoding tried first. The valid values of this parameter are MIME-preferred charset names from the IANA Charset Registry, like ISO-8859-5, UTF-8 or Shift_JIS. -
strip_whitespace: This enables/disables white-space stripping. Valid values are the boolean constantstrueandfalse. (And for backward compatibility, strings"yes","no","true","false"). The default value (i.e. when you don't use this parameter) depends on the FreeMarker configuration set by the programmers, but it should betruefor new projects. -
strip_text: When enabled, all top-level text in a template is removed when the template is parsed. This does not affect text within macros, directives, or interpolations. Valid values are the boolean constantstrueandfalse. (And for backward compatibility, strings"yes","no","true","false"). The default value (i.e. when you don't use this parameter) isfalse. -
strict_syntax: This turns on/off ``strict syntax''. Valid values are the boolean constantstrueandfalse. (And for backward compatibility, strings"yes","no","true","false"). The default value (i.e. when you don't use this parameter) depends on the FreeMarker configuration set by the programmers, but it should betruefor new projects. (Programmers: you must set explicitly this setting totruefor this:config.setStrictSyntaxMode(true);) For more information read: Deprecated FTL constructs/Old FTL syntax -
ns_prefixes: This is a hash that associates prefixes with node namespaces. For example:{"e":"http://example.com/ebook", "vg":"http://example.com/vektorGraphics"}. This is mostly used with XML processing where the prefixes can be used in XML queries, but it also influences the working of directivesvisitandrecurse. Only one prefix can be registered for the same node namespace (otherwise an error will occur), so there is one-to-one relation between prefixes and node namespaces. PrefixesDandNare reserved. If you register prefixD, then other than you associate the node namespace with prefixD, you also set the default node namespace. PrefixNcan't be registered; it is used to denote nodes with no node namespace in certain places, when (and only when) prefixDis registered. (To see the usage of default node namespace,N, and prefixes in general, see the part about XML processing andvisitandrecursein the reference.) The effect ofns_prefixesis limited to a single FTL namespace, namely, to the FTL namespace that was created for the template. This also means thatns_prefixeshas effect only when an FTL namespace is created for the template that contains it, otherwise thens_prefixesparameter has no effect. An FTL namespace is made for a template when: (a) the template is the ``main'' template, that is, it is not invoked as a result of an<#include ...>, but it is directly invoked (with theprocessJava method of classTemplateorEnvironment); (b) the template is invoked directly with<#import ...>. -
attributes: This is a hash that associates arbitrary attributes (name-value pairs) to the template. The values of the attributes can be of any type (string, number, sequence... etc.). FreeMarker doesn't try to understand the meaning of the attributes. It's up to the application that encapsulates FreeMarker (as a Web application framework). Thus, the set of allowed attributes and their semantic is application (Web application framework) dependent. Programmers: you can get the attributes associated with aTemplateobject with itsgetCustomAttributeNamesandgetCustomAttributemethods (inherited fromfreemarker.core.Configurable). As the template attributes are associated with theTemplateobject when the template is parsed, the attributes can be read anytime, the template need not be executed. The methods mentioned return the attribute values unwrapped, that is, with FreeMarker independent type asjava.util.List.
This directive also determines if the template uses angle
bracket syntax (e.g. <#include 'foo.ftl'>)
or square bracket
syntax (e.g. [#include 'foo.ftl']).
Simply, the syntax used for this directive will be the syntax used
for the whole template, regardless of the FreeMarker configuration
settings.