freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject [43/50] incubator-freemarker-site git commit: 2.3.26-nightly docs preview
Date Mon, 13 Mar 2017 10:58:19 GMT
http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/52c070a9/builds/2.3.26-nightly/dgui_misc_autoescaping.html
----------------------------------------------------------------------
diff --git a/builds/2.3.26-nightly/dgui_misc_autoescaping.html b/builds/2.3.26-nightly/dgui_misc_autoescaping.html
new file mode 100644
index 0000000..f234ea6
--- /dev/null
+++ b/builds/2.3.26-nightly/dgui_misc_autoescaping.html
@@ -0,0 +1,718 @@
+<!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>Auto-escaping and output formats - Apache 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="Apache FreeMarker Manual">
+<meta property="og:title" content="Auto-escaping and output formats">
+<meta property="og:locale" content="en_US">
+<meta property="og:url" content="http://freemarker.org/docs/dgui_misc_autoescaping.html">
+<link rel="canonical" href="http://freemarker.org/docs/dgui_misc_autoescaping.html">
+<link rel="icon" href="favicon.png" type="image/png">
+<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono">
+<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979">
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-55420501-1', 'auto');
+ga('send', 'pageview');
+</script>
+</head>
+<body itemscope itemtype="https://schema.org/Code">
+    <meta itemprop="url" content="http://freemarker.org/docs/">
+    <meta itemprop="name" content="Apache 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://freemarker.org" role="banner">            <img itemprop="image" src="logo.png" alt="FreeMarker">
+</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc
 h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></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">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui.html"><span itemprop="name">Template Author&#39;s Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui_misc.html"><span itemprop="name">Miscellaneous</span></a></li><li class="step-3" itempro
 p="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui_misc_autoescaping.html"><span itemprop="name">Auto-escaping and output formats</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</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 = ["Apache FreeMarker Manual","Template Author\'s Guide","Miscellaneous","Auto-escaping and output formats"];</script>
+      <script src="toc.js?1489402528979"></script>
+      <script src="docgen-resources/main.min.js?1489402528979"></script>
+  </div>
+<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="dgui_misc_namespace.html"><span>Previous</span></a><a class="paging-arrow next" href="dgui_misc_whitespace.html"><span>Next</span></a></div><div class="title-wrapper">
+<h1 class="content-header header-section1" id="dgui_misc_autoescaping" itemprop="headline">Auto-escaping and output formats</h1>
+</div></div><div class="page-menu">
+<div class="page-menu-title">Page Contents</div>
+<ul><li><a class="page-menu-link" href="#dgui_misc_autoescaping_outputformat" data-menu-target="dgui_misc_autoescaping_outputformat">Output formats</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_overrideoformat" data-menu-target="dgui_misc_autoescaping_overrideoformat">Overriding the output format in templates</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_disableautoesc" data-menu-target="dgui_misc_autoescaping_disableautoesc">Disabling auto escaping</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_movalues" data-menu-target="dgui_misc_autoescaping_movalues">"Markup output" values</a></li><li><a class="page-menu-link" href="#autoid_28" data-menu-target="autoid_28">Further details and tricky cases</a><ul><li><a class="page-menu-link" href="#dgui_misc_autoescaping_nonmarkupof" data-menu-target="dgui_misc_autoescaping_nonmarkupof">Non-markup output formats</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_m
 ixingoutputformats" data-menu-target="dgui_misc_autoescaping_mixingoutputformats">Inserting markup output values from other markups</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_concatenation" data-menu-target="dgui_misc_autoescaping_concatenation">Markup output values and the "+"
+operator</a></li><li><a class="page-menu-link" href="#dgui_misc_autoescaping_stringliteral" data-menu-target="dgui_misc_autoescaping_stringliteral">${...} inside string literals</a></li><li><a class="page-menu-link" href="#autoid_29" data-menu-target="autoid_29">Combined output formats</a></li></ul></li></ul> </div><p>This is a <em>detailed</em> tutorial to
+        auto-escaping and related concepts; for the bare minimum, <a href="dgui_quickstart_template.html#dgui_quickstart_template_autoescaping">read this
+        instead</a>.</p>  <div class="callout note">
+    <strong class="callout-label">Note:</strong>
+
+          <p>The kind of automatic escaping described here requires at
+          least FreeMarker 2.3.24. If you have to use an earlier version, use
+          the deprecated <a href="ref_directive_escape.html"><code>escape</code>
+          directive</a> instead.</p>
+          </div>
+
+          
+
+
+
+<h2 class="content-header header-section2" id="dgui_misc_autoescaping_outputformat">Output formats</h2>
+
+
+          
+
+          <p>Each template has an associated output format <span class="marked-for-programmers">(a
+          <code class="inline-code">freemarker.core.OutputFormat</code> instance)</span>.
+          The output format dictates the escaping rules, which is applied on
+          all <code class="inline-code">${<em class="code-color">...</em>}</code>-s (and
+          <code class="inline-code">#{<em class="code-color">...</em>}</code>-s) that aren&#39;t
+          <a href="#dgui_misc_autoescaping_stringliteral">inside a string
+          literal</a>. It also specifies a MIME type (e.g.
+          <code class="inline-code">&quot;text/HTML&quot;</code>) and a canonical name (e.g.
+          <code class="inline-code">&quot;HTML&quot;</code>) that the embedding application/framework
+          can use for its own purposes.</p>
+
+          <p>It&#39;s the programmer&#39;s responsibility to <a href="pgui_config_outputformatsautoesc.html">associate output format
+          to templates</a>. Furthermore it&#39;s recommended that FreeMarker is
+          configured so that templates with <code class="inline-code">ftlh</code> and
+          <code class="inline-code">ftlx</code> file extensions are automatically associated
+          with the HTML and XML output formats, respectively.</p>
+
+          <p><a name="topic.predefinedOutputFormats"></a>The predefined output
+          formats are:</p>
+
+            <div class="table-responsive">
+    <table class="table">
+
+            <thead>
+              <tr>
+                <th>Name</th>
+
+
+                <th>Description</th>
+
+
+                <th>MIME Type</th>
+
+
+                <th>Default implementation
+                (<code class="inline-code">freemarker.core.*</code>)</th>
+
+              </tr>
+
+            </thead>
+
+
+            <tbody>
+              <tr>
+                <td><code class="inline-code">HTML</code></td>
+
+
+                <td>Escapes <code class="inline-code">&lt;</code>, <code class="inline-code">&gt;</code>,
+                <code class="inline-code">&amp;</code>, <code class="inline-code">&quot;</code>,
+                <code class="inline-code">&#39;</code> as <code class="inline-code">&amp;lt;</code>,
+                <code class="inline-code">&amp;gt;</code>, <code class="inline-code">&amp;amp;</code>,
+                <code class="inline-code">&amp;quot;</code>,
+                <code class="inline-code">&amp;#39;</code></td>
+
+
+                <td><code class="inline-code">text/html</code></td>
+
+
+                <td><code class="inline-code">HTMLOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">XHTML</code></td>
+
+
+                <td>Escapes <code class="inline-code">&lt;</code>, <code class="inline-code">&gt;</code>,
+                <code class="inline-code">&amp;</code>, <code class="inline-code">&quot;</code>,
+                <code class="inline-code">&#39;</code> as <code class="inline-code">&amp;lt;</code>,
+                <code class="inline-code">&amp;gt;</code>, <code class="inline-code">&amp;amp;</code>,
+                <code class="inline-code">&amp;quot;</code>,
+                <code class="inline-code">&amp;#39;</code></td>
+
+
+                <td><code class="inline-code">application/xhtml+xml</code></td>
+
+
+                <td><code class="inline-code">XHTMLOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+            </tbody>
+
+
+            <tbody>
+              <tr>
+                <td><code class="inline-code">XML</code></td>
+
+
+                <td>Escapes <code class="inline-code">&lt;</code>, <code class="inline-code">&gt;</code>,
+                <code class="inline-code">&amp;</code>, <code class="inline-code">&quot;</code>,
+                <code class="inline-code">&#39;</code> as <code class="inline-code">&amp;lt;</code>,
+                <code class="inline-code">&amp;gt;</code>, <code class="inline-code">&amp;amp;</code>,
+                <code class="inline-code">&amp;quot;</code>,
+                <code class="inline-code">&amp;apos;</code></td>
+
+
+                <td><code class="inline-code">application/xml</code></td>
+
+
+                <td><code class="inline-code">XMLOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">RTF</code></td>
+
+
+                <td>Escapes <code class="inline-code">{</code>, <code class="inline-code">}</code>,
+                <code class="inline-code">\</code> as <code class="inline-code">\{</code>,
+                <code class="inline-code">\}</code>, <code class="inline-code">\\</code></td>
+
+
+                <td><code class="inline-code">application/rtf</code></td>
+
+
+                <td><code class="inline-code">RTFOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">undefined</code></td>
+
+
+                <td>Doesn&#39;t escape. Prints markup output values (concept
+                explained <a href="#dgui_misc_autoescaping_movalues">later</a>) from
+                other output formats as is. The default output format used
+                when no output format was explicitly set in the
+                configuration.</td>
+
+
+                <td>None (<code class="inline-code">null</code>)</td>
+
+
+                <td><code class="inline-code">UndefinedOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">plainText</code></td>
+
+
+                <td>Doesn&#39;t escape.</td>
+
+
+                <td><code class="inline-code">text/plain</code></td>
+
+
+                <td><code class="inline-code">PlainTextOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">JavaScript</code></td>
+
+
+                <td>Doesn&#39;t escape.</td>
+
+
+                <td><code class="inline-code">application/javascript</code></td>
+
+
+                <td><code class="inline-code">JavaScriptOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">JSON</code></td>
+
+
+                <td>Doesn&#39;t escape.</td>
+
+
+                <td><code class="inline-code">application/json</code></td>
+
+
+                <td><code class="inline-code">JSONOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+
+              <tr>
+                <td><code class="inline-code">CSS</code></td>
+
+
+                <td>Doesn&#39;t escape.</td>
+
+
+                <td><code class="inline-code">text/css</code></td>
+
+
+                <td><code class="inline-code">CSSOutputFormat.INSTANCE</code></td>
+
+              </tr>
+
+            </tbody>
+
+              </table>
+  </div>
+
+
+          <p>The programmers can add their your own output formats, so this
+          is maybe not all the output formats in your application!</p>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="dgui_misc_autoescaping_overrideoformat">Overriding the output format in templates</h2>
+
+
+          <p>Especially in legacy applications, you will often find that
+          the output format is <code class="inline-code">undefined</code> (you can check
+          that with <code class="inline-code">${.output_format}</code>), and so no automatic
+          escaping is happening. In other cases, a common output format (like
+          HTML) is set for all templates, but a few templates need a different
+          output format. In any case, the output format of a template can be
+          enforced in the <a href="ref_directive_ftl.html">the
+          <code>ftl</code> header</a>:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#ftl output_format=&quot;XML&quot;&gt;
+${&quot;&#39;&quot;}  &lt;#-- Prints: &amp;apos; --&gt;</pre></div>
+
+          <p>Above, the output format was referred by its name shown in the
+          earlier table <em>(looked up via
+          <code class="inline-code">Configuration.getOutputFormat(String name)</code>,
+          actually)</em>.</p>
+
+            <div class="callout note">
+    <strong class="callout-label">Note:</strong>
+
+            <p>If escaping doesn&#39;t happen after adding the above
+            <code class="inline-code">ftl</code> header, then <code class="inline-code">&lt;#ftl
+            output_format=&quot;XML&quot; auto_esc=true&gt;</code> might helps (and
+            that means that FreeMarker was configured to use
+            "disable" auto-escaping <em>policy</em>,
+            which is generally not recommended).</p>
+            </div>
+
+
+          <p>The output format can also be applied to only a section of a
+          template, like:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- Let&#39;s assume we have &quot;HTML&quot; output format by default. --&gt;
+${&quot;&#39;&quot;}  &lt;#-- Prints: &amp;#39; --&gt;
+&lt;#outputformat &quot;XML&quot;&gt;
+  ${&quot;&#39;&quot;}  &lt;#-- Prints: &amp;apos; --&gt;
+&lt;/#outputformat&gt;
+${&quot;&#39;&quot;}  &lt;#-- Prints: &amp;#39; --&gt;</pre></div>
+
+          <p>Basically, each position in a template has an associated
+          output format, and as you saw above, it might not be the same
+          everywhere in the template. This association sticks to the positions
+          and won&#39;t change as the template executes. So if, for example, you
+          call a macro from inside an <code class="inline-code">outputformat</code> block
+          and the called macro is defined outside that block, it won&#39;t get the
+          output format of it. Or, if you have a macro that&#39;s defined in a
+          template with HTML output format, no mater from where you call it,
+          that macro will always execute with HTML output format. This is like
+          if you were coloring each characters of the template files by output
+          format in the text editor, and then later when the templates are
+          executed, it only considers the color of the statement being
+          executed. This gives you firm control over the output format and
+          hence escaping; you don&#39;t have to consider the possible execution
+          paths that can lead to a point.</p>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="dgui_misc_autoescaping_disableautoesc">Disabling auto escaping</h2>
+
+
+          <p>For a single interpolation you can disable auto-escaping with
+          <a href="ref_builtins_string.html#ref_builtin_no_esc"><code>?no_esc</code></a>:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- Let&#39;s assume we have &quot;HTML&quot; output format by default. --&gt;
+${&#39;&lt;b&gt;test&lt;/b&gt;&#39;}  &lt;#-- prints: &amp;lt;b&amp;gt;test&amp;lt;/b&amp;gt; --&gt;
+${&#39;&lt;b&gt;test&lt;/b&gt;&#39;<strong>?no_esc</strong>}  &lt;#-- prints: &lt;b&gt;test&lt;/b&gt; --&gt;</pre></div>
+
+          <p>You can also disable auto escaping for a whole section with
+          the <a href="ref_directive_noautoesc.html"><code>noautoesc</code>
+          directive</a>:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">${&#39;&amp;&#39;}  &lt;#-- prints: &amp;amp; --&gt;
+<strong>&lt;#noautoesc&gt;</strong>
+  ${&#39;&amp;&#39;}  &lt;#-- prints: &amp; --&gt;
+  ...
+  ${&#39;&amp;&#39;}  &lt;#-- prints: &amp; --&gt;
+<strong>&lt;/#noautoesc&gt;</strong>
+${&#39;&amp;&#39;}  &lt;#-- prints: &amp;amp; --&gt;</pre></div>
+
+          <p>Just like <code class="inline-code">outputformat</code>, this only applies
+          to the part that&#39;s literally inside the block
+          ("coloring" logic).</p>
+
+          <p>Auto-escaping can also be disabled for the whole template in
+          the <code class="inline-code">ftl</code> header. It can then be re-enabled for a
+          section with the <a href="ref_directive_autoesc.html"><code>autoesc</code>
+          directive</a>:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#ftl <strong>autoesc=false</strong>&gt;
+${&#39;&amp;&#39;}  &lt;#-- prints: &amp; --&gt;
+<strong>&lt;#autoesc&gt;</strong>
+  ${&#39;&amp;&#39;}  &lt;#-- prints: &amp;amp; --&gt;
+  ...
+  ${&#39;&amp;&#39;}  &lt;#-- prints: &amp;amp; --&gt;
+<strong>&lt;/#autoesc&gt;</strong>
+${&#39;&amp;&#39;}  &lt;#-- prints: &amp; --&gt;</pre></div>
+
+          <p>You can also force escaping for an individual interpolation
+          when escaping is disabled, with <a href="ref_builtins_string.html#ref_builtin_esc"><code>?esc</code></a>:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#ftl <strong>autoesc=false</strong>&gt;
+${&#39;&amp;&#39;}  &lt;#-- prints: &amp; --&gt;
+${&#39;&amp;&#39;<strong>?esc</strong>}  &lt;#-- prints: &amp;amp; --&gt;</pre></div>
+
+          <p>Naturally, both <code class="inline-code">autoesc</code> and
+          <code class="inline-code">?esc</code> works inside <code class="inline-code">noautoesc</code>
+          blocks too.</p>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="dgui_misc_autoescaping_movalues">"Markup output" values</h2>
+
+
+          <p>In FTL, <a href="dgui_datamodel_basics.html">values have
+          type</a>, like string, number, boolean, etc. One such type is
+          called "markup output". A value of that type is a piece
+          of text that&#39;s already in the output format (like HTML), and hence
+          needs no further escaping. We have already produced such values
+          earlier:</p>
+
+          <ul>
+            <li>
+              <p><code class="inline-code"><em class="code-color">s</em>?esc</code>
+              creates a markup output value out of a string value by escaping
+              all special characters in it.</p>
+            </li>
+
+            <li>
+              <p><code class="inline-code"><em class="code-color">s</em>?no_esc</code>
+              creates a markup output value out of a string value by assuming
+              that the string already stores markup and so needs no further
+              escaping</p>
+            </li>
+          </ul>
+
+          <p>These can be useful outside
+          <code class="inline-code">${<em class="code-color">...</em>}</code> too. For
+          example, here the caller of the <code class="inline-code">infoBox</code> macro can
+          decide if the message is plain text (hence needs escaping) or HTML
+          (hence it mustn&#39;t be escaped):</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+
+&lt;@infoBox &quot;Foo &amp; bar&quot; /&gt;
+&lt;@infoBox &quot;Foo &lt;b&gt;bar&lt;/b&gt;&quot;?no_esc /&gt;
+
+&lt;#macro infoBox message&gt;
+  &lt;div class=&quot;infoBox&quot;&gt;
+    ${message}
+  &lt;/div&gt;
+&lt;/#macro&gt;</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">  &lt;div class=&quot;infoBox&quot;&gt;
+    Foo &amp;amp; bar
+  &lt;/div&gt;
+  &lt;div class=&quot;infoBox&quot;&gt;
+    Foo &lt;b&gt;bar&lt;/b&gt;
+  &lt;/div&gt;</pre></div>
+
+          <p>Another case where you get a markup output value is output
+          capturing:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+&lt;#assign captured&gt;&lt;b&gt;Test&lt;/b&gt;&lt;/#assign&gt;
+Just a string: ${&quot;&lt;b&gt;Test&lt;/b&gt;&quot;}
+Captured output: ${captured}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">Just a string: &amp;lt;b&amp;gt;Test&amp;lt;/b&amp;gt;
+Captured output: &lt;b&gt;Test&lt;/b&gt;</pre></div>
+
+          <p>Because the captured output is markup output, it wasn&#39;t
+          auto-escaped.</p>
+
+          <p>It&#39;s important that markup output values aren&#39;t strings, and
+          aren&#39;t automatically coerced to strings. Thus
+          <code class="inline-code">?upper_case</code>, <code class="inline-code">?starts_with</code>
+          etc., will give an error with them. You won&#39;t be able to pass them
+          to Java methods for <code class="inline-code">String</code> parameters either. But
+          sometimes you need the markup that&#39;s behind the value as a string,
+          which you can get as
+          <code class="inline-code"><em class="code-color">markupOutput</em>?markup_string</code>.
+          Be sure you know what you are doing though. Applying string
+          operations on markup (as opposed to on plain text) can result in
+          invalid markup. Also there&#39;s the danger of unintended double
+          escaping.</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+
+&lt;#assign markupOutput1=&quot;&lt;b&gt;Test&lt;/b&gt;&quot;?no_esc&gt;
+&lt;#assign markupOutput2=&quot;Foo &amp; bar&quot;?esc&gt;
+
+As expected:
+${markupOutput1}
+${markupOutput2}
+
+Possibly unintended double escaping:
+${markupOutput1?markup_string}
+${markupOutput2?markup_string}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">As expected:
+&lt;b&gt;Test&lt;/b&gt;
+Foo &amp;amp; bar
+
+Possibly unintended double escaping:
+&amp;lt;b&amp;gt;Test&amp;lt;/b&amp;gt;
+Foo &amp;amp;amp; bar</pre></div>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_28">Further details and tricky cases</h2>
+
+
+          
+            
+
+
+
+<h3 class="content-header header-section3" id="dgui_misc_autoescaping_nonmarkupof">Non-markup output formats</h3>
+
+
+            <p>An output format is said to be a non-markup format if it
+            defines no escaping rules. Examples of such output formats are the
+            <code class="inline-code">undefined</code> format and the
+            <code class="inline-code">plainText</code> format.</p>
+
+            <p>These formats produce no <a href="#dgui_misc_autoescaping_movalues">markup output
+            values</a>, hence you can&#39;t use <code class="inline-code">?esc</code> or
+            <code class="inline-code">?no_esc</code> when they are the current format. You
+            can use output capturing (like <code class="inline-code">&lt;#assign
+            captured&gt;<em class="code-color">...</em>&lt;/#assign&gt;</code>),
+            but the resulting value will be a string, not a markup output
+            value.</p>
+
+            <p>Furthermore, you aren&#39;t allowed to use the
+            <code class="inline-code">autoesc</code> directive or <code class="inline-code">&lt;#ftl
+            auto_esc=true&gt;</code> when the current output format is
+            non-markup.</p>
+
+            <p>Using constructs that aren&#39;t supported by the current output
+            format will give <a href="gloss.html#gloss.parseTimeError">parse-time
+            error</a>.</p>
+          
+
+          
+            
+
+
+
+<h3 class="content-header header-section3" id="dgui_misc_autoescaping_mixingoutputformats">Inserting markup output values from other markups</h3>
+
+
+            <p>Each <a href="#dgui_misc_autoescaping_movalues">markup
+            output value</a> has an associated <a href="#dgui_misc_autoescaping_outputformat">output
+            format</a>. When a markup output value is inserted with
+            <code class="inline-code">${<em class="code-color">...</em>}</code> (or
+            <code class="inline-code">#{<em class="code-color">...</em>}</code>), it has to
+            be converted to the current output format at the point of
+            insertion (if they differ). As of this writing (2.3.24), such
+            output format conversion will only be successful if the value to
+            convert was created by escaping plain text:</p>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+
+&lt;#assign mo1 = &quot;Foo&#39;s bar {}&quot;?esc&gt;
+HTLM: ${mo1}
+XML:  &lt;#outputformat &#39;XML&#39;&gt;${mo1}&lt;/#outputformat&gt;
+RTF:  &lt;#outputformat &#39;RTF&#39;&gt;${mo1}&lt;/#outputformat&gt;
+
+&lt;#assign mo2&gt;&lt;p&gt;Test&lt;/#assign&gt;
+HTML: ${mo2}
+XML:  &lt;#attempt&gt;&lt;#outputformat &#39;XML&#39;&gt;${mo2}&lt;/#outputformat&gt;&lt;#recover&gt;Failed&lt;/#attempt&gt;
+RTF:  &lt;#attempt&gt;&lt;#outputformat &#39;RTF&#39;&gt;${mo2}&lt;/#outputformat&gt;&lt;#recover&gt;Failed&lt;/#attempt&gt;</pre></div>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-output">HTLM: Foo&amp;#39;s bar {}
+XML:  Foo&amp;apos;s bar {}
+RTF:  Foo&#39;s bar \{\}
+
+HTML: &lt;p&gt;Test
+XML:  Failed
+RTF:  Failed</pre></div>
+
+            <p>But, an output format can also chose to insert pieces of
+            other output formats as is, without converting them. Among the
+            standard output formats, <code class="inline-code">undefined</code> is like
+            that, which is the output format used for templates for which no
+            output format was specified in the configuration:</p>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;undefined&quot; output format here. --&gt;
+
+&lt;#outputformat &quot;HTML&quot;&gt;&lt;#assign htmlMO&gt;&lt;p&gt;Test&lt;/#assign&gt;&lt;/#outputformat&gt;
+&lt;#outputformat &quot;XML&quot;&gt;&lt;#assign xmlMO&gt;&lt;p&gt;Test&lt;/p&gt;&lt;/#assign&gt;&lt;/#outputformat&gt;
+&lt;#outputformat &quot;RTF&quot;&gt;&lt;#assign rtfMO&gt;\par Test&lt;/#assign&gt;&lt;/#outputformat&gt;
+HTML: ${htmlMO}
+XML:  ${xmlMO}
+RTF:  ${rtfMO}</pre></div>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-output">HTML: &lt;p&gt;Test
+XML:  &lt;p&gt;Test&lt;/p&gt;
+RTF:  \par Test</pre></div>
+          
+
+          
+            
+
+
+
+<h3 class="content-header header-section3" id="dgui_misc_autoescaping_concatenation">Markup output values and the "+"
+            operator</h3>
+
+
+            <p>As you certainly know, if one of the sides of the
+            <code class="inline-code">+</code> operator is a string then <a href="dgui_template_exp.html#dgui_template_exp_stringop_concatenation">it does
+            concatenation</a>. If there&#39;s a <a href="#dgui_misc_autoescaping_movalues">markup output
+            value</a> in one side, the other side gets promoted to markup
+            output value of the same output format (if it&#39;s not already that),
+            by escaping its string value, and finally the two markups are
+            concatenated to form a new markup output value. Example:</p>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+${&quot;&lt;h1&gt;&quot;?no_esc + &quot;Foo &amp; bar&quot; + &quot;&lt;/h1&gt;&quot;?no_esc}</pre></div>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-output">&lt;h1&gt;Foo &amp;amp; bar&lt;/h1&gt;</pre></div>
+
+            <p>If the two sides of the <code class="inline-code">+</code> operator are
+            markup values of different output formats, the right side operand
+            is converted to the output format of the left side. If that&#39;s not
+            possible, then the left side operand is converted to the output
+            format of the right side. If that isn&#39;t possible either, that&#39;s an
+            error. (See the <a href="#dgui_misc_autoescaping_mixingoutputformats">limitations
+            of conversions here</a>.)</p>
+          
+
+          
+            
+
+
+
+<h3 class="content-header header-section3" id="dgui_misc_autoescaping_stringliteral">${...} inside string literals</h3>
+
+
+            <p>When <code class="inline-code">${<em class="code-color">...</em>}</code> is
+            used inside string <em>expressions</em> (e.g., in
+            <code class="inline-code">&lt;#assign s = &quot;Hello ${name}!&quot;&gt;</code>), it&#39;s
+            just a shorthand of using the <code class="inline-code">+</code> operator
+            (<code class="inline-code">&lt;#assign s = &quot;Hello&quot; + name + &quot;!&quot;&gt;</code>).
+            Thus, <code class="inline-code">${<em class="code-color">...</em>}</code>-s
+            inside string expressions aren&#39;t auto-escaped, but of course when
+            the resulting concatenated string is printed later, it will be
+            possibly auto-escaped.</p>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#-- We assume that we have &quot;HTML&quot; output format by default. --&gt;
+&lt;#assign name = &quot;Foo &amp; Bar&quot;&gt;
+
+&lt;#assign s = &quot;&lt;p&gt;Hello ${name}!&quot;&gt;
+${s}
+&lt;p&gt;Hello ${name}!
+
+To prove that s didn&#39;t contain the value in escaped form:
+${s?replace(&#39;&amp;&#39;), &#39;and&#39;}</pre></div>
+
+            
+
+<div class="code-wrapper"><pre class="code-block code-output">&amp;lt;p&amp;gt;Hello Foo &amp;amp; Bar!
+&lt;p&gt;Hello Foo &amp;amp; Bar!
+
+To prove that &quot;s&quot; didn&#39;t contain the value in escaped form:
+&amp;lt;p&amp;gt;Hello Foo and Bar!</pre></div>
+          
+
+          
+            
+
+
+
+<h3 class="content-header header-section3" id="autoid_29">Combined output formats</h3>
+
+
+            <p>Combined output formats are output formats that are created
+            ad-hoc from other output formats by nesting them into each other,
+            so that the escaping of both output formats are applied. <a href="ref_directive_outputformat.html#topic.combinedOutputFormats">They are discussed
+            here...</a></p>
+          
+        <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="dgui_misc_namespace.html"><span>Previous</span></a><a class="paging-arrow next" href="dgui_misc_whitespace.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 class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href
 ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><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="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p>
+<p class="copyright">
+© <span itemprop="copyrightYear">1999</span>–2017
+<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p>
+</div></div></div></body>
+</html>

http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/52c070a9/builds/2.3.26-nightly/dgui_misc_namespace.html
----------------------------------------------------------------------
diff --git a/builds/2.3.26-nightly/dgui_misc_namespace.html b/builds/2.3.26-nightly/dgui_misc_namespace.html
new file mode 100644
index 0000000..ba514ea
--- /dev/null
+++ b/builds/2.3.26-nightly/dgui_misc_namespace.html
@@ -0,0 +1,315 @@
+<!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>Namespaces - Apache 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="Apache FreeMarker Manual">
+<meta property="og:title" content="Namespaces">
+<meta property="og:locale" content="en_US">
+<meta property="og:url" content="http://freemarker.org/docs/dgui_misc_namespace.html">
+<link rel="canonical" href="http://freemarker.org/docs/dgui_misc_namespace.html">
+<link rel="icon" href="favicon.png" type="image/png">
+<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Roboto:500,700,400,300|Droid+Sans+Mono">
+<link rel="stylesheet" type="text/css" href="docgen-resources/docgen.min.css?1489402528979">
+<script>
+(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
+ga('create', 'UA-55420501-1', 'auto');
+ga('send', 'pageview');
+</script>
+</head>
+<body itemscope itemtype="https://schema.org/Code">
+    <meta itemprop="url" content="http://freemarker.org/docs/">
+    <meta itemprop="name" content="Apache 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://freemarker.org" role="banner">            <img itemprop="image" src="logo.png" alt="FreeMarker">
+</a><ul class="tabs"><li><a href="http://freemarker.org/">Home</a></li><li class="current"><a href="index.html">Manual</a></li><li><a class="external" href="api/index.html">Java API</a></li></ul><ul class="secondary-tabs"><li><a class="tab icon-heart" href="http://freemarker.org/contribute.html" title="Contribute"><span>Contribute</span></a></li><li><a class="tab icon-bug" href="https://issues.apache.org/jira/browse/FREEMARKER/" title="Report a Bug"><span>Report a Bug</span></a></li><li><a class="tab icon-download" href="http://freemarker.org/freemarkerdownload.html" title="Download"><span>Download</span></a></li></ul></div></div><div class="header-bottom-bg"><div class="site-width search-row"><a href="index.html" class="navigation-header">Manual</a><div class="navigation-header"></div><form method="get" class="search-form" action="search-results.html"><fieldset><legend class="sr-only">Search form</legend><label for="search-field" class="sr-only">Search query</label><input id="searc
 h-field" name="q" type="search" class="search-input" placeholder="Search" spellcheck="false" autocorrect="off" autocomplete="off"><button type="submit" class="search-btn"><span class="sr-only">Search</span></button></fieldset></form></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">Apache FreeMarker Manual</span></a></li><li class="step-1" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui.html"><span itemprop="name">Template Author&#39;s Guide</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui_misc.html"><span itemprop="name">Miscellaneous</span></a></li><li class="step-3" itempro
 p="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="dgui_misc_namespace.html"><span itemprop="name">Namespaces</span></a></li></ul><div class="bookmarks" title="Bookmarks"><span class="sr-only">Bookmarks:</span><ul class="bookmark-list"><li><a href="alphaidx.html">Alpha. index</a></li><li><a href="gloss.html">Glossary</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions</a></li><li><a href="ref_builtins_alphaidx.html">?builtins</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_specvar.html">.spec_vars</a></li><li><a href="app_faq.html">FAQ</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 = ["Apache FreeMarker Manual","Template Author\'s Guide","Miscellaneous","Namespaces"];</script>
+      <script src="toc.js?1489402528979"></script>
+      <script src="docgen-resources/main.min.js?1489402528979"></script>
+  </div>
+<div class="col-right"><div class="page-content"><div class="page-title"><div class="pagers top"><a class="paging-arrow previous" href="dgui_misc_var.html"><span>Previous</span></a><a class="paging-arrow next" href="dgui_misc_autoescaping.html"><span>Next</span></a></div><div class="title-wrapper">
+<h1 class="content-header header-section1" id="dgui_misc_namespace" itemprop="headline">Namespaces</h1>
+</div></div><div class="page-menu">
+<div class="page-menu-title">Page Contents</div>
+<ul><li><a class="page-menu-link" href="#autoid_23" data-menu-target="autoid_23">Creating a library</a></li><li><a class="page-menu-link" href="#autoid_24" data-menu-target="autoid_24">Writing the variables of imported namespaces</a></li><li><a class="page-menu-link" href="#autoid_25" data-menu-target="autoid_25">Namespaces and data-model</a></li><li><a class="page-menu-link" href="#autoid_26" data-menu-target="autoid_26">The life-cycle of namespaces</a></li><li><a class="page-menu-link" href="#autoid_27" data-menu-target="autoid_27">Auto-importing</a></li></ul> </div><p>When you run templates, you have a (possibly empty) set of
+        variables that you have created with <code class="inline-code">assign</code> and
+        <code class="inline-code">macro</code> and <code class="inline-code">function</code> directives
+        (see in the <a href="dgui_misc_var.html">previous chapter</a>). A
+        set of template-made variables like that is called a <strong>namespace</strong>. In simple cases you use only one
+        namespace, the <strong>main namespace</strong>.
+        Whenever you define a variable in the main template (macros and
+        functions are also variables, mind you), or in templates <a href="ref_directive_include.html#ref.directive.include"><code>include</code>-d</a> in
+        it, that&#39;s where the variable are created. The key property of a
+        namespace is that the variable name uniquely identifies a value in it
+        (i.e, you can&#39;t have multiple variables in it with the same name in
+        the same namespace).</p><p>Sometimes you want to build reusable collection of macros,
+        functions, and other variables, which we call a <strong>library</strong>. It&#39;s important that a library can use
+        its own namespace, to avoid accidental name clashes. Consider, you may
+        have many names in that library, and you intend to use the library in
+        many templates, maybe even reuse it in several projects. It becomes
+        impractical to keep track of where the library used in another
+        template accidentally hides variables from the data-model, or what
+        names you shouldn&#39;t assign to in the template to avoid overwriting the
+        variables of the library. If you have multiple libraries used in the
+        same template, this becomes even harder to track. So you should use a
+        separate namespace for the variables of each library.</p>
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_23">Creating a library</h2>
+
+
+          <p>Here&#39;s a simple library, which contains a
+          <code class="inline-code">copyright</code> macro and a <code class="inline-code">mail</code>
+          string:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#macro copyright date&gt;
+  &lt;p&gt;Copyright (C) ${date} Someone. All rights reserved.&lt;/p&gt;
+&lt;/#macro&gt;
+
+&lt;#assign mail = &quot;user@example.com&quot;&gt;</pre></div>
+
+          <p>Save this into the <code class="inline-code">lib/example.ftl</code> file
+          (inside the directory where you store the templates). Then create a
+          template, let&#39;s say, <code class="inline-code">some_web_page.ftl</code>, and use
+          the library in it:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#<strong>import</strong> &quot;/lib/example.ftl&quot; as <strong>e</strong>&gt;
+
+Some Web page...
+&lt;@<strong>e</strong>.copyright date=&quot;1999-2002&quot;/&gt;
+${<strong>e</strong>.mail}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">Some Web page...
+  &lt;p&gt;Copyright (C) 1999-2002 Someone. All rights reserved.&lt;/p&gt;
+user@example.com</pre></div>
+
+          <p>Note the <a href="ref_directive_import.html#ref.directive.import"><code>import</code>
+          directive</a> above, and the subsequent usage of the
+          "<code class="inline-code">e</code>" variable.
+          <code class="inline-code">import</code> is similar to the perhaps already familiar
+          <a href="ref_directive_include.html#ref.directive.include"><code>include</code>
+          directive</a>, but it will create an empty namespace and will run
+          <code class="inline-code">lib/example.ftl</code> in that namespace. So
+          <code class="inline-code">lib/example.ftl</code> will find itself in a clean
+          world, where only the variables of the data-models are visible (and
+          the globals), and will create its two variables
+          (<code class="inline-code">copyright</code> and <code class="inline-code">mail</code>) in this
+          clean namespace. But you will need to access those two variables
+          from another namespace (the main namespace), thus, the
+          <code class="inline-code">import</code> directive creates a hash variable
+          (<code class="inline-code">e</code> in this case) to access the namespace it has
+          created . That variable is in the namespace that the
+          <code class="inline-code">import</code>-ing template uses, and acts as a window to
+          the namespace of the imported library.</p>
+
+          <p>To demonstrate that the two namespaces are separate, consider
+          the example below. Replace <code class="inline-code">lib/example.ftl</code> with
+          this:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#macro copyright date&gt;
+  &lt;p&gt;Copyright (C) ${date} Someone. All rights reserved.
+  &lt;br&gt;Email: <strong>${mail}</strong>&lt;/p&gt;
+&lt;/#macro&gt;
+
+&lt;#assign mail = &quot;user@example.com&quot;&gt;</pre></div>
+
+          <p>and <code class="inline-code">some_web_page.ftl</code> with this:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#import &quot;/lib/example.ftl&quot; as e&gt;
+<strong>&lt;#assign mail=&quot;other@example.com&quot;&gt;</strong>
+&lt;@e.copyright date=&quot;1999-2002&quot;/&gt;
+${e.mail}
+${mail}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">  &lt;p&gt;Copyright (C) 1999-2002 Someone. All rights reserved.
+  &lt;br&gt;Email: <strong>user@example.com</strong>&lt;/p&gt;
+user@example.com
+other@example.com</pre></div>
+
+          <p>As you can see, the <code class="inline-code">mail</code> variable assigned
+          in <code class="inline-code">some_web_page.ftl</code> is separate from the
+          <code class="inline-code">mail</code> variable assigned in the imported
+          library.</p>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_24">Writing the variables of imported namespaces</h2>
+
+
+          <p>Sometimes you want to create or replace a variable in an
+          imported namespace. You can do that with the
+          <code class="inline-code">assign</code> directive and its
+          <code class="inline-code">namespace</code> parameter:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#import &quot;/lib/example.ftl&quot; as e&gt;
+${my.mail}
+&lt;#assign mail=&quot;other@example.com&quot; <strong>in e</strong>&gt;
+${my.mail}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">user@example.com
+other@example.com</pre></div>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_25">Namespaces and data-model</h2>
+
+
+          <p>The variables of the data-model are visible from everywhere.
+          For example, if you have a variable called <code class="inline-code">user</code>
+          in the data-model, <code class="inline-code">lib/example.ftl</code> will access
+          that, exactly like <code class="inline-code">some_web_page.ftl</code> does:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#macro copyright date&gt;
+  &lt;p&gt;Copyright (C) ${date} <strong>${user}</strong>. All rights reserved.&lt;/p&gt;
+&lt;/#macro&gt;</pre></div>
+
+          <p>Assuming <code class="inline-code">user</code> is "John
+          Doe":</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#import &quot;/lib/my_test.ftl&quot; as my&gt;
+User is: ${user}
+&lt;@my.copyright date=&quot;1999-2002&quot;/&gt;</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">User is: John Doe
+  &lt;p&gt;Copyright (C) 1999-2002 John Doe. All rights reserved.&lt;/p&gt;</pre></div>
+
+          <p>Don&#39;t forget that the variables in the namespace (the
+          variables you create with <code class="inline-code">assign</code>,
+          <code class="inline-code">macro</code>, and <code class="inline-code">function</code>
+          directives) have precedence over the variables of the data-model
+          when you are in that namespace. So generally, if a library is
+          interested in a data-model variable, it doesn&#39;t assign to the same
+          name.</p>
+
+            <div class="callout note">
+    <strong class="callout-label">Note:</strong>
+
+            <p>In some unusual applications you want to create variables in
+            the template that are visible from all namespaces, exactly like
+            the variables of the data-model. While templates can&#39;t change the
+            data-model, it&#39;s possible to achieve similar effect with the
+            <code class="inline-code">global</code> directive; see the <a href="ref_directive_global.html#ref.directive.global">reference</a>.</p>
+            </div>
+
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_26">The life-cycle of namespaces</h2>
+
+
+          <p>A namespace is identified by the path used in the
+          <code class="inline-code">import</code> directive (after it was normalized to an
+          absolute path). If you try to <code class="inline-code">import</code> with
+          equivalent paths for multiple times, it will create the namespace
+          and run the template for only the first invocation of
+          <code class="inline-code">import</code>. The later <code class="inline-code">import</code>-s
+          with equivalent paths will just assign the same namespace to the
+          variable specified after the <code class="inline-code">as</code> keyword. For
+          example:</p>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-template">&lt;#import &quot;/lib/example.ftl&quot; as e&gt;
+&lt;#import &quot;/lib/example.ftl&quot; as e2&gt;
+&lt;#import &quot;/lib/example.ftl&quot; as e3&gt;
+${e.mail}, ${e2.mail}, ${e3.mail}
+&lt;#assign mail=&quot;other@example.com&quot; in my&gt;
+${e.mail}, ${e2.mail}, ${e3.mail}</pre></div>
+
+          
+
+<div class="code-wrapper"><pre class="code-block code-output">user@example.com, user@example.com, user@example.com
+other@example.com, other@example.com, other@example.com</pre></div>
+
+          <p>As you access the same namespace through <code class="inline-code">e</code>,
+          <code class="inline-code">e2</code>, and <code class="inline-code">e3</code>, the
+          <code class="inline-code">email</code> has changed in all of them at once. The
+          practical importance of this is that when you import the same
+          library in multiple templates, only one namespace will be
+          initialized and created for the library, which will be shared by all
+          the importing templates.</p>
+
+          <p>Note that namespaces are not hierarchical; it doesn&#39;t mater
+          what namespace are you in when <code class="inline-code">import</code> creates
+          another namespace. For example, when you <code class="inline-code">import</code>
+          namespace N2 while you are in name space N1, N2 will not be inside
+          N1. N1 just gets the same N2 that you get if you
+          <code class="inline-code">import</code> N2 when you are in the main
+          namespace.</p>
+
+          <p>Each <a href="gloss.html#gloss.templateProcessingJob">template
+          processing job</a> has its own private set of namespaces. Each
+          template processing job is a separate universe that exists only for
+          the short period while the main template is rendered, and then it
+          vanishes with all its populated namespaces. Thus, whenever we say
+          that "<code class="inline-code">import</code> is called for the first
+          time", we always mean the first time within the lifespan of a
+          single template processing job.</p>
+        
+          
+
+
+
+<h2 class="content-header header-section2" id="autoid_27">Auto-importing</h2>
+
+
+          <p>When you have to import the same libraries again and again in
+          many templates, know that the Java programmers (or whoever is
+          responsible for configuring FreeMarker) can specify auto-imports,
+          which are imports that are automatically done in all templates. Auto
+          imports can also be configured to be "lazy" (since
+          FreeMarker 2.3.25), which means that they are only done when the
+          imported library is actually used in the template. See the Java API
+          documentation for more details: <a href="http://freemarker.org/docs/api/freemarker/template/Configuration.html#setAutoImports-java.util.Map-">Configuration.setAutoImports</a>,
+          <a href="http://freemarker.org/docs/api/freemarker/template/Configuration.html#setLazyAutoImports-java.lang.Boolean-">Configuration.setLazyAutoImports</a>.</p>
+        <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="dgui_misc_var.html"><span>Previous</span></a><a class="paging-arrow next" href="dgui_misc_autoescaping.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 class="column"><h3 class="column-header">Overview</h3><ul><li><a href="http://freemarker.org/">What is FreeMarker?</a></li><li><a href="http://freemarker.org/freemarkerdownload.html">Download</a></li><li><a href="app_versions.html">Version history</a></li><li><a href="http://freemarker.org/history.html">About us</a></li><li><a itemprop="license" href="app_license.html">License</a></li></ul></div><div class="column"><h3 class="column-header">Handy stuff</h3><ul><li><a href="http://freemarker-online.kenshoo.com/">Try template online</a></li><li><a href="dgui_template_exp.html#exp_cheatsheet">Expressions cheatsheet</a></li><li><a href="ref_directive_alphaidx.html">#directives</a></li><li><a href="ref_builtins_alphaidx.html">?built_ins</a></li><li><a href="ref_specvar.html">.special_vars</a></li></ul></div><div class="column"><h3 class="column-header">Community</h3><ul><li><a href
 ="https://github.com/freemarker/freemarker">FreeMarker on Github</a></li><li><a href="https://twitter.com/freemarker">Follow us on Twitter</a></li><li><a href="https://issues.apache.org/jira/browse/FREEMARKER/">Report a bug</a></li><li><a href="http://stackoverflow.com/questions/ask?tags=freemarker">Ask a question</a></li><li><a href="http://freemarker.org/mailing-lists.html">Mailing lists</a></li></ul></div></div><div class="col-right"><ul class="social-icons"><li><a class="github" href="https://github.com/freemarker/freemarker">Github</a></li><li><a class="twitter" href="https://twitter.com/freemarker">Twitter</a></li><li><a class="stack-overflow" href="http://stackoverflow.com/questions/ask?tags=freemarker">Stack Overflow</a></li></ul><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="2017-03-13T10:55:28Z" title="Monday, March 13, 2017 10:55:28 AM GMT">2017-03-13 10:55:28 GMT</time>, for Freemarker 2.3.26 </p>
+<p class="copyright">
+© <span itemprop="copyrightYear">1999</span>–2017
+<a itemtype="http://schema.org/Organization" itemprop="copyrightHolder" href="http://apache.org/">The Apache Software Foundation</a>. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. </p>
+</div></div></div></body>
+</html>


Mime
View raw message