blob: dd93ac24e94f888188970606e76293abf59e9e62 [file] [log] [blame]
<!doctype html>
<!-- Generated by FreeMarker/Docgen from DocBook -->
<html lang="en" class="page-type-section">
<head prefix="og: http://ogp.me/ns#">
<meta charset="utf-8">
<title>ftl - FreeMarker Manual</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="format-detection" content="telephone=no">
<meta property="og:site_name" content="FreeMarker Manual">
<meta property="og:title" content="ftl">
<meta property="og:locale" content="en_US">
<meta property="og:url" content="http://example.com/ref_directive_ftl.html">
<link rel="canonical" href="http://example.com/ref_directive_ftl.html">
<link rel="icon" href="favicon.png" type="image/png">
<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1594338519184">
</head>
<body itemscope itemtype="https://schema.org/Code">
<meta itemprop="url" content="http://example.com/">
<meta itemprop="name" content="FreeMarker Manual">
<!--[if lte IE 9]>
<div style="background-color: #C00; color: #fff; padding: 12px 24px;">Please use a modern browser to view this website.</div>
<![endif]--><div class="header-top-bg"><div class="site-width header-top"><a class="logo" href="http://example.com" role="banner"> <img itemprop="image" src="logo.png" alt="My Logo">
</a></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">FreeMarker Manual</a><div class="navigation-header"></div></div><div class="site-width breadcrumb-row"><ul class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList"><li class="step-0" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="index.html"><span itemprop="name">FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref.html"><span itemprop="name">Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_directives.html"><span itemprop="name">Directive Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_directive_ftl.html"><span itemprop="name">ftl</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="ref.html">Reference</a></li><li><a href="app_faq.html">FAQ</a></li><li><a href="preface.html#test_target">Bőregér</a></li><li><a href="api/index.html">API</a></li><li><a href="../index.html">Home</a></li></ul></div></div></div> <div class="main-content site-width">
<div class="content-wrapper">
<div id="table-of-contents-wrapper" class="col-left">
<script>var breadcrumb = ["FreeMarker Manual","Reference","Directive Reference","ftl"];</script>
<script src="toc.js?1594338519184"></script>
<script src="docgen-resources/main.min.js?1594338519184"></script>
</div>
<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="ref_directive_stop.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_directive_t.html"><span>Next</span></a></div><div class="title-wrapper">
<h1 class="content-header header-section1" id="ref_directive_ftl" itemprop="headline">ftl</h1>
</div></div><div class="page-menu">
<div class="page-menu-title">Page Contents</div>
<ul><li><a class="page-menu-link" href="#autoid_114" data-menu-target="autoid_114">Synopsis</a></li><li><a class="page-menu-link" href="#autoid_115" data-menu-target="autoid_115">Description</a></li></ul> </div><a name="ref.directive.ftl"></a>
<h2 class="content-header header-section2" id="autoid_114">Synopsis</h2>
<pre class="metaTemplate">
<code class="inline-code">&lt;#ftl <em class="code-color">param1</em>=<em class="code-color">value1</em> <em class="code-color">param2</em>=<em class="code-color">value2</em> <em class="code-color">...</em> <em class="code-color">paramN</em>=<em class="code-color">valueN</em>&gt;</code>
</pre>
<p>Where:</p>
<ul>
<li>
<code class="inline-code"><em class="code-color">param1</em></code>,
<code class="inline-code"><em class="code-color">param2</em></code>, ...etc.:
Name of the parameter. Not an expression. Allowed parameters
are: <code class="inline-code">encoding</code>,
<code class="inline-code">strip_whitespace</code>,
<code class="inline-code">strip_text</code>, ...etc. See below.
</li>
<li>
<code class="inline-code"><em class="code-color">value1</em></code>,
<code class="inline-code"><em class="code-color">value2</em></code>, ...etc.:
The value of parameter. This must be a constant expression (as
<code class="inline-code">true</code>, or <code class="inline-code">&quot;ISO-8859-5&quot;</code>, or
<code class="inline-code">{x:1, y:2}</code>). It can&#39;t use variables.
</li>
</ul>
<h2 class="content-header header-section2" id="autoid_115">Description</h2>
<p>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 <a href="gloss.html#gloss.whiteSpace">white-space</a> before this directive
will be ignored. The old-syntax (<code class="inline-code">#</code>-less) format
of this directive is not supported.</p>
<p>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.</p>
<p>Parameters:</p>
<ul>
<li>
<p><code class="inline-code">encoding</code>: With this you can specify the
encoding (charset) of the template in the template file itself.
<span class="marked-for-programmers">(That is, this will be the
<code class="inline-code">encoding</code> setting of the newly created
<code class="inline-code">Template</code>, and not even the
<code class="inline-code">encoding</code> parameter to
<code class="inline-code">Configuration.getTemplate</code> can override
it)</span>. Note however, that FreeMarker will try to find and
interpret the <code class="inline-code">ftl</code> directive first with the
automatically guessed encoding (which depends on the FreeMarker
configuration set by the programmers), and only then realizes if
the <code class="inline-code">ftl</code> directive dictates something
different, and re-read the template with the new encoding. Thus,
the template must be valid FTL until the end of
<code class="inline-code">ftl</code> tag 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.</p>
</li>
<li>
<p><code class="inline-code">strip_whitespace</code>: This enables/disables
<a href="dgui_misc_whitespace.html#dgui_misc_whitespace_stripping">white-space
stripping</a>. Valid values are the boolean constants
<code class="inline-code">true</code> and <code class="inline-code">false</code>. (And for
backward compatibility, strings <code class="inline-code">&quot;yes&quot;</code>,
<code class="inline-code">&quot;no&quot;</code>, <code class="inline-code">&quot;true&quot;</code>,
<code class="inline-code">&quot;false&quot;</code>). The default value (i.e. when you
don&#39;t use this parameter) depends on the FreeMarker
configuration set by the programmers, but it should be
<code class="inline-code">true</code> for new projects.</p>
</li>
<li>
<p><code class="inline-code">strip_text</code>: 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 constants
<code class="inline-code">true</code> and <code class="inline-code">false</code>. (And for
backward compatibility, strings <code class="inline-code">&quot;yes&quot;</code>,
<code class="inline-code">&quot;no&quot;</code>, <code class="inline-code">&quot;true&quot;</code>,
<code class="inline-code">&quot;false&quot;</code>). The default value (i.e. when you
don&#39;t use this parameter) is <code class="inline-code">false</code>.</p>
</li>
<li>
<p><code class="inline-code">strict_syntax</code>: This turns on/off
``strict syntax&#39;&#39;. Valid values are the boolean constants
<code class="inline-code">true</code> and <code class="inline-code">false</code>. (And for
backward compatibility, strings <code class="inline-code">&quot;yes&quot;</code>,
<code class="inline-code">&quot;no&quot;</code>, <code class="inline-code">&quot;true&quot;</code>,
<code class="inline-code">&quot;false&quot;</code>). The default value (i.e. when you
don&#39;t use this parameter) depends on the FreeMarker
configuration set by the programmers, but it should be
<code class="inline-code">true</code> for new projects. <span class="marked-for-programmers">(Programmers: you must set explicitly this
setting to <code class="inline-code">true</code> for this:
<code class="inline-code">config.setStrictSyntaxMode(true);</code>)</span>
For more information read: <a href="ref_depr_oldsyntax.html">Deprecated FTL constructs/Old FTL syntax</a></p>
</li>
<li>
<p><code class="inline-code">ns_prefixes</code>: This is a hash that
associates prefixes with node namespaces. For example:
<code class="inline-code">{&quot;e&quot;:&quot;http://example.com/ebook&quot;,
&quot;vg&quot;:&quot;http://example.com/vektorGraphics&quot;}</code>. This is
mostly used with XML processing where the prefixes can be used
in XML queries, but it also influences the working of <a href="ref_directive_visit.html">directives
<code>visit</code> and <code>recurse</code></a>.
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. Prefixes
<code class="inline-code">D</code> and <code class="inline-code">N</code> are reserved. If
you register prefix <code class="inline-code">D</code>, then other than you
associate the node namespace with prefix <code class="inline-code">D</code>,
you also set the default node namespace. Prefix
<code class="inline-code">N</code> can&#39;t be registered; it is used to denote
nodes with no node namespace in certain places, when (and only
when) prefix <code class="inline-code">D</code> is registered. (To see the
usage of default node namespace, <code class="inline-code">N</code>, and
prefixes in general, see the part about <a href="xgui.html">XML
processing</a> and <a href="ref_directive_visit.html"><code>visit</code> and
<code>recurse</code></a> in the reference.) The effect
of <code class="inline-code">ns_prefixes</code> is limited to a single <a href="dgui_misc_namespace.html">FTL namespace</a>, namely, to
the FTL namespace that was created for the template. This also
means that <code class="inline-code">ns_prefixes</code> has effect only when
an FTL namespace is created for the template that contains it,
otherwise the <code class="inline-code">ns_prefixes</code> parameter has no
effect. An FTL namespace is made for a template when: (a) the
template is the ``main&#39;&#39; template, that is, it is not invoked as
a result of an <code class="inline-code">&lt;#include ...&gt;</code>, but it
is directly invoked (<span class="marked-for-programmers">with the
<code class="inline-code">process</code> Java method of class
<code class="inline-code">Template</code> or
<code class="inline-code">Environment</code></span>); (b) the template is
invoked directly with <code class="inline-code">&lt;#import
...&gt;</code>.</p>
</li>
<li>
<p><code class="inline-code">attributes</code>: 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&#39;t try to
understand the meaning of the attributes. It&#39;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.
<span class="marked-for-programmers">Programmers: you can get the
attributes associated with a <code class="inline-code">Template</code> object
with its <code class="inline-code">getCustomAttributeNames</code> and
<code class="inline-code">getCustomAttribute</code> methods (inherited from
<code class="inline-code">freemarker.core.Configurable</code>). As the
template attributes are associated with the
<code class="inline-code">Template</code> object 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 as
<code class="inline-code">java.util.List</code>.</span></p>
</li>
</ul>
<p>This directive also determines if the template uses angle
bracket syntax (e.g. <code class="inline-code">&lt;#include &#39;foo.ftl&#39;&gt;</code>)
or <a href="dgui_misc_alternativesyntax.html">square bracket
syntax</a> (e.g. <code class="inline-code">[#include &#39;foo.ftl&#39;]</code>).
Simply, the syntax used for this directive will be the syntax used
for the whole template, regardless of the FreeMarker configuration
settings.</p>
<div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_directive_stop.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_directive_t.html"><span>Next</span></a></div></div></div></div> </div>
</div>
<div class="site-footer"><div class="site-width"><div class="footer-top"><div class="col-left sitemap"></div><div class="col-right"><a class="xxe" href="http://www.xmlmind.com/xmleditor/" rel="nofollow" title="Edited with XMLMind XML Editor"><span>Edited with XMLMind XML Editor</span></a></div></div><div class="footer-bottom"> <p class="last-generated">
Last generated:
<time itemprop="dateModified" datetime="2020-07-09T23:48:39Z" title="Thursday, July 9, 2020 11:48:39 PM GMT">2020-07-09 23:48:39 GMT</time> </p>
<p class="copyright">
© <span itemprop="copyrightYear">1999</span>–2020
<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="https://apache.org/">The Apache Software Foundation</a> </p>
</div></div></div></body>
</html>