| <!doctype html> |
| <!-- Generated by FreeMarker/Docgen from DocBook --> |
| <html lang="en" class="page-type-chapter"> |
| <head prefix="og: http://ogp.me/ns#"> |
| <meta charset="utf-8"> |
| <title>Special Variable Reference - 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="Special Variable Reference"> |
| <meta property="og:locale" content="en_US"> |
| <meta property="og:url" content="http://example.com/ref_specvar.html"> |
| <link rel="canonical" href="http://example.com/ref_specvar.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_specvar.html"><span itemprop="name">Special Variable Reference</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","Special Variable Reference"];</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_visit.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_reservednames.html"><span>Next</span></a></div><div class="title-wrapper"> |
| <h1 class="content-header header-chapter" id="ref_specvar" itemprop="headline">Special Variable Reference</h1> |
| </div></div><p>Special variables are variables defined by the FreeMarker engine |
| itself. To access them, you use the |
| <code class="inline-code">.<em class="code-color">variable_name</em></code> syntax. For |
| example, you can't write simply <code class="inline-code">version</code>; you have to |
| write <code class="inline-code">.version</code>.</p><p>The supported special variables are:</p><ul> |
| <li> |
| <code class="inline-code">data_model</code>: A hash that you can use to |
| access the data-model directly. That is, variables you did with |
| <code class="inline-code">global</code> directive are not visible here. |
| </li> |
| |
| <li> |
| <code class="inline-code">error</code> (available since FreeMarker |
| 2.3.1): This variable accessible in the body of the <a href="ref_directive_attempt.html#ref.directive.attempt"><code>recover</code> |
| directive</a>, where it stores the error message of the error we |
| recover from. |
| </li> |
| |
| <li> |
| <code class="inline-code">globals</code>: A hash that you can use to access |
| the globally accessible variables: the data-model and the variables |
| created with <code class="inline-code">global</code> directive. Note that |
| variables created with <code class="inline-code">assign</code> or |
| <code class="inline-code">macro</code> are not globals, thus they never hide the |
| variables when you use <code class="inline-code">globals</code>. |
| </li> |
| |
| <li> |
| <code class="inline-code">language</code>: Returns the language part |
| of the current value of the locale setting. For example if |
| <code class="inline-code">.locale</code> is <code class="inline-code">en_US</code>, then |
| <code class="inline-code">.lang</code> is <code class="inline-code">en</code>. |
| </li> |
| |
| <li> |
| <code class="inline-code">locale</code>: Returns the current value |
| of the locale setting. This is a string, for example |
| <code class="inline-code">en_US</code>. For more information about locale strings |
| <a href="ref_directive_setting.html#ref.directive.setting">see the |
| <code>setting</code> directive</a>. |
| </li> |
| |
| <li> |
| <code class="inline-code">locals</code>: A hash that you can use to access |
| the local variables (the variables created with the |
| <code class="inline-code">local</code> directive, and the parameters of |
| macro). |
| </li> |
| |
| <li> |
| <code class="inline-code">main</code>: A hash that you can use to access the |
| main <a href="dgui_misc_namespace.html">namespace</a>. Note that |
| global variables like the variables of data-model are |
| <em>not</em> visible through this hash. |
| </li> |
| |
| <li> |
| <code class="inline-code">namespace</code>: A hash that you can use to |
| access the current <a href="dgui_misc_namespace.html">namespace</a>. Note that global |
| variables like the variables of data-model are |
| <em>not</em> visible through this hash. |
| </li> |
| |
| <li> |
| <code class="inline-code">node</code> (alias <code class="inline-code">current_node</code> |
| for historical reasons): The node you are currently processing with |
| the visitor pattern (i.e. with the <a href="ref_directive_visit.html"><code>visit</code>, |
| <code>recurse</code>, ...etc. directives</a>). Also, it |
| initially stores the root node when you use the <a href="pgui_misc_ant.html">FreeMarker XML Ant task</a>. |
| </li> |
| |
| <li> |
| <code class="inline-code">output_encoding</code> (available since |
| FreeMarker 2.3.1): Returns the name of the current output charset. |
| This special variable is not existent if the framework that |
| encapsulates FreeMarker doesn't specify the output charset for |
| FreeMarker. <span class="marked-for-programmers">(Programmers can read more |
| about charset issues <a href="pgui_misc_charset.html">here...</a>)</span> |
| </li> |
| |
| <li> |
| <code class="inline-code">template_name</code>: The name of the current |
| template (available since FreeMarker 2.3.14). |
| </li> |
| |
| <li> |
| <code class="inline-code">url_escaping_charset</code> (available |
| since FreeMarker 2.3.1): If exists, it stores the name of the |
| charset that should be used for URL escaping. If this variable |
| doesn't exist that means that nobody has specified what charset |
| should be used for URL encoding yet. In this case the <a href="ref_builtins_string.html#ref_builtin_url"><code>url</code> built-in</a> |
| uses the charset specified by the <code class="inline-code">output_encoding</code> |
| special variable for URL encoding; custom mechanism may follow the |
| same logic. <span class="marked-for-programmers">(Programmers can read more |
| about charset issues <a href="pgui_misc_charset.html">here...</a>)</span> |
| </li> |
| |
| <li> |
| <code class="inline-code">vars</code>: Expression |
| <code class="inline-code">.vars.foo</code> returns the same variable as expression |
| <code class="inline-code">foo</code>. It's useful if for some reasons you have to |
| use square bracket syntax, since that works only for hash |
| subvariables, so you need an artificial parent hash. For example, to |
| read a top-level variable that has a strange name that would confuse |
| FreeMarker, you can write |
| <code class="inline-code">.vars["A strange name!"]</code>. Or, to access a |
| top-level variable with dynamic name given with variable |
| <code class="inline-code">varName</code> you can write |
| <code class="inline-code">.vars[varName]</code>. Note that the hash returned by |
| <code class="inline-code">.vars</code> does not support <code class="inline-code">?keys</code> |
| and <code class="inline-code">?values</code>. |
| </li> |
| |
| <li> |
| <code class="inline-code">version</code>: Returns the FreeMarker |
| version number as string, for example <code class="inline-code">2.2.8</code>. This |
| can be used to check which FreeMarker version does your application |
| use, but note that this special variable does not exist prior to the |
| 2.3-final or 2.2.8 versions. The version number of non-final |
| releases contain abbreviation ``pre'' for ``preview'' (e.g. |
| <code class="inline-code">2.3pre6</code>), or abbrevation ``rc'' for ``release |
| candidate''. |
| </li> |
| </ul><div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_directive_visit.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_reservednames.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> |