http://git-wip-us.apache.org/repos/asf/incubator-freemarker-site/blob/52c070a9/builds/2.3.26-nightly/ref_builtins_expert.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/ref_builtins_expert.html b/builds/2.3.26-nightly/ref_builtins_expert.html new file mode 100644 index 0000000..b722d1a --- /dev/null +++ b/builds/2.3.26-nightly/ref_builtins_expert.html @@ -0,0 +1,762 @@ +<!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>Seldom used and expert built-ins - 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="Seldom used and expert built-ins"> +<meta property="og:locale" content="en_US"> +<meta property="og:url" content="http://freemarker.org/docs/ref_builtins_expert.html"> +<link rel="canonical" href="http://freemarker.org/docs/ref_builtins_expert.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="ref.html"><span itemprop="name">Template Language Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins.html"><span itemprop="name">Built-in Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins_expert.html"><span itemprop="name">Seldom used and expert built-ins</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 Language Reference","Built-in Reference","Seldom used and expert built-ins"];</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="ref_builtins_type_independent.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_directives.html"><span>Next</span></a></div><div class="title-wrapper"> +<h1 class="content-header header-section1" id="ref_builtins_expert" itemprop="headline">Seldom used and expert built-ins</h1> +</div></div><div class="page-menu"> +<div class="page-menu-title">Page Contents</div> +<ul><li><a class="page-menu-link" href="#ref_buitin_api_and_has_api" data-menu-target="ref_buitin_api_and_has_api">api, has_api</a></li><li><a class="page-menu-link" href="#ref_builtin_numType" data-menu-target="ref_builtin_numType">byte, double, float, int, long, short</a></li><li><a class="page-menu-link" href="#ref_builtin_eval" data-menu-target="ref_builtin_eval">eval</a></li><li><a class="page-menu-link" href="#ref_builtin_has_content" data-menu-target="ref_builtin_has_content">has_content</a></li><li><a class="page-menu-link" href="#ref_builtin_interpret" data-menu-target="ref_builtin_interpret">interpret</a></li><li><a class="page-menu-link" href="#ref_builtin_isType" data-menu-target="ref_builtin_isType">is_...</a></li><li><a class="page-menu-link" href="#ref_builtin_markup_string" data-menu-target="ref_builtin_markup_string">markup_string</a></li><li><a class="page-menu-link" href="#ref_builtin_namespace" data-menu-target="ref_builtin_namespace">namespace</a></li><li><a cla ss="page-menu-link" href="#ref_builtin_new" data-menu-target="ref_builtin_new">new</a></li><li><a class="page-menu-link" href="#ref_builtin_numToDate" data-menu-target="ref_builtin_numToDate">number_to_date, number_to_time, number_to_datetime</a></li></ul> </div><p>These are the built-ins that normally you should not use, but in + exceptional situations (debugging, advanced macros) they can be + useful. If you need to use these in your normal page templates, you + may revisit the data-model so you don't need to use these.</p> + + + + +<h2 class="content-header header-section2" id="ref_buitin_api_and_has_api">api, has_api</h2> + + + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>These built-ins exists since FreeMarker 2.3.22</p> + </div> + + + <p><code class="inline-code"><em class="code-color">value</em>?api</code> + provides access to the API (usually, the Java API) of + <code class="inline-code"><em class="code-color">value</em></code>, like + <code class="inline-code"><em class="code-color">value</em>?api.<em class="code-color">someJavaMethod()</em></code> + or + <code class="inline-code"><em class="code-color">value</em>?api.<em class="code-color">someBeanProperty</em></code>, + if the value itself supports exposing its API. This meant to be used + rarely, when you need to call a Java method of an object, but the + by-design simplistic view of the value that FreeMarker exposes to + the templates hides that, and there's no equivalent built-in either. + For example, when you put a <code class="inline-code">Map</code> into the + data-model (and you are using the default object wrapper), + <code class="inline-code">myMap.myMethod()</code> in a template basically + translates to <code class="inline-code">((Method) + myMap.get("myMethod")).invoke(...)</code> in Java, thus you can't + call <code class="inline-code">myMethod</code>. If, however, you write + <code class="inline-code">myMap?api.myMethod()</code> instead, that means + <code class="inline-code">myMap.myMethod()</code> in Java. Similarly, + <code class="inline-code">myMap?api.myProperty</code> translates to + <code class="inline-code">myMap.getMyProperty()</code> in Java, instead of to + <code class="inline-code">myMap.get("myProperty")</code>.</p> + + <p><em>You should avoid using <code class="inline-code">api</code>, and + rely on the capabilities of the FTL types and the related built-ins + as far as possible.</em> For example, don't use + <code class="inline-code">users?api.size()</code>, but + <code class="inline-code">users?size</code>. The variation that uses + <code class="inline-code">?api</code> is more verbose, slower, more easily breaks + when FreeMarker configuration settings are changed, and most + importantly, more prone to break as the technical details of the + data-model change. For example, if <code class="inline-code">users</code> is + changed from a <code class="inline-code">List</code> to an array, + <code class="inline-code">users?size</code> will keep working, while + <code class="inline-code">users?api.size()</code> will break.</p> + + <p>Avoid calling methods that <em>modify</em> an + object (especially <code class="inline-code">Map</code>-s and + <code class="inline-code">Collection</code>-s) or that aren't thread safe from + other reasons. Templates usually aren't expected to modify the + objects exposed to them, just to display them. Thus the application + may passes some objects to multiple (possibly concurrent) template + processings.</p> + + <p>The <code class="inline-code">api</code> built-in is not everywhere + available, some requirements has to be met:</p> + + <ul> + <li> + <p>The <code class="inline-code">api_builtin_enabled</code> configuration + setting must be set to <code class="inline-code">true</code>. Its default is + <code class="inline-code">false</code> (at least as of 2.3.22) for not + lowering the security of existing applications.</p> + </li> + + <li> + <p>The value itself has to support it. We are talking about + the value as the template sees it, which is created from the + original object (that's coming from the data-model or from a + Java method return value) value via <a href="pgui_datamodel_objectWrapper.html">object wrapping</a>. + Hence, this depends on the <code class="inline-code">object_wrapper</code> + FreeMarker configuration setting, and on the class of the + wrapped (the original) object:</p> + + <ul> + <li> + <p>When the object wrapper is a + <code class="inline-code">DefaultObjectWrapper</code> with its + <code class="inline-code">incompatibleImprovements</code> set to 2.3.22 or + higher (<a href="pgui_datamodel_objectWrapper.html#topic.defaultObjectWrapperIcI">see + how to set it here</a>), FTL values made from + <code class="inline-code">Map</code>-s and <code class="inline-code">List</code>-s + support <code class="inline-code">?api</code>. (Actually, what matters is + that its <code class="inline-code">useAdaptersForContainer</code> property + is set to <code class="inline-code">true</code>, but that's the default + with said <code class="inline-code">incompatibleImprovements</code>.) + Other <code class="inline-code">java.util.Collections</code> (such as + <code class="inline-code">Set</code>-s) only support + <code class="inline-code">?api</code> if + <code class="inline-code">DefaultObjectWrapper</code>'s + <code class="inline-code">forceLegacyNonListCollections</code> property is + set to <code class="inline-code">false</code> (the default is + <code class="inline-code">true</code> for better out-of-the-box backward + compatibility).</p> + </li> + + <li> + <p>When wrapped with pure + <code class="inline-code">BeansWrapper</code>, all values support + <code class="inline-code">?api</code>.</p> + </li> + + <li> + <p>Custom <code class="inline-code">TemplateModel</code>-s can support + <code class="inline-code">?api</code> by implementing the + <code class="inline-code">freemarker.template.TemplateModelWithAPISupport</code> + interface.</p> + </li> + </ul> + </li> + </ul> + + <p>Using <code class="inline-code">?api</code> when it's not allowed in the + configuration or when the value doesn't support it will abort + template processing with error.</p> + + <p>Whether a value supports <code class="inline-code">?api</code> can be + checked like + <code class="inline-code"><em class="code-color">value</em>?has_api</code>, which + returns a boolean value. Note that the result of + <code class="inline-code">?has_api</code> isn't influenced by the + <code class="inline-code">api_builtin_enabled</code> setting.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_numType">byte, double, float, int, long, short</h2> + + + + + + + + + + + + + + + + + + + + + + + <p>Returns a <code class="inline-code">SimpleNumber</code> which contains the + same value as the original variable, but uses + <code class="inline-code">java.lang.<em class="code-color">Type</em></code> for the + internal representation of the value. This is useful if a method is + overloaded, or if a <code class="inline-code">TemplateModel</code> unwrapper has + problem with automatically choosing the suitable + <code class="inline-code">java.lang.*</code> type. Note that since version 2.3.9 + the unwrapper has been improved substantially, so you will hardly + ever need to use these built-ins to convert between numerical types, + except for resolving ambiguity in overloaded method + invocation.</p> + + <p>The <code class="inline-code">long</code> built-in can also be used with + date, time and date-time values to get the value as + <code class="inline-code">java.util.Date.getTime()</code> would return. This is + useful if you have to call a Java methods that expect a timestamp as + a <code class="inline-code">long</code>.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_eval">eval</h2> + + + + + + + <p>This built-in evaluates a string as an FTL expression. For + example <code class="inline-code">"1+2"?eval</code> returns number 3.</p> + + <p>The evaluated expression sees the same variables (such as + locals) that are visible at the place of the invocation of + <code class="inline-code">eval</code>. That is, it behaves similarly as if in + place of <code class="inline-code"><em class="code-color">s</em>?eval</code> you + had the <em>value of</em> + <code class="inline-code"><em class="code-color">s</em></code> there. Except, it + can't use <a href="ref_builtins_loop_var.html">loop variable + built-ins</a> that refer to a loop variable that was created + outside <code class="inline-code"><em class="code-color">s</em></code>.</p> + + <p>Regarding the configuration settings that affect the parsing + (like syntax) and evaluation the rules are the same as with the + <a href="#ref_builtin_interpret"><code>interpret</code> + built-in</a>.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_has_content">has_content</h2> + + + + + <p>It is <code class="inline-code">true</code> if the variable exists (and + isn't Java <code class="inline-code">null</code>) and is not "empty", + otherwise it is <code class="inline-code">false</code>. The meaning of + "empty" depends on the concrete case. This follows + intuitive common-sense ideas. The following are empty: a string with + 0 length, a <a href="dgui_misc_autoescaping.html#dgui_misc_autoescaping_movalues">markup + output value</a> with 0 length markup, a sequence or hash with no + sub variables, a collection which has passed the last element. If + the value is not of any of these types, then it counts as non-empty + if it's a number or a date or a boolean (e.g. <code class="inline-code">0</code> + and <code class="inline-code">false</code> are not empty), otherwise it counts as + empty. Note that when your data-model implements multiple template + model interfaces you may get unexpected results. However, when in + doubt you can use always use <code class="inline-code">expr!?size > 0</code> or + <code class="inline-code">expr!?length > 0</code> instead of + <code class="inline-code">expr?has_content</code>.</p> + + <p>This buit-in is exceptional in that you can use the + parentheses trick like with the <a href="dgui_template_exp.html#dgui_template_exp_missing_default">default value + operator</a>. That is, you can write both + <code class="inline-code">product.color?has_content</code> and + <code class="inline-code">(product.color)?has_content</code>. The first doesn't + handle the case when <code class="inline-code">product</code> is missing, the last + does.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_interpret">interpret</h2> + + + + + <p>This built-in parses a string as an FTL template, and returns + an user-defined directive that executes that template, just as if a + template with that content were <a href="ref_directive_include.html"><code>include</code>-d</a> + at that point. Example:</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#assign x=["a", "b", "c"]> +<#assign templateSource = r"<#list x as y>${y}</#list>"> +<#-- Note: That r was needed so that the ${y} is not interpreted above --> +<#assign inlineTemplate = templateSource?interpret> +<@inlineTemplate /></pre></div> + + <p>The output:</p> + + + +<div class="code-wrapper"><pre class="code-block code-output">abc</pre></div> + + <p>As you can see, <code class="inline-code">inlineTemplate</code> is a + user-defined directive that, when executed, runs the template whose + content is the value of <code class="inline-code">templateSource</code>.</p> + + <p>The name of the template created by + <code class="inline-code">interpret</code> is the name of the template that calls + <code class="inline-code">interpret</code>, plus + <code class="inline-code">"->anonymous_interpreted"</code>. For example, if the + template that calls the built-in is + <code class="inline-code">"foo/bar.ftl"</code>, then the name of the resulting + template is + <code class="inline-code">"foo/bar.ftl->anonymous_interpreted"</code>. Thus, + relative paths inside the interpreted template are relative to this + path (i.e., the base directory will be <code class="inline-code">"foo"</code>), + and errors inside the interpreted template will point to this + generated template name.</p> + + <p>For more helpful error messages, you can override the template + name part after the <code class="inline-code">"->"</code>. For example, let's + say <code class="inline-code">mailTemplateSource</code> comes from the + <code class="inline-code">mail_template</code> database table, and in the case of + error, you want the error log to contain the database ID of the + failing template:</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#assign inlineTemplate = [mailTemplateSource, "mail_templates id=${mailTemplateId}"]?interpret></pre></div> + + <p>As you can see, <code class="inline-code">interpret</code> can be applied on + a sequence of two items, in which case the first item is the FTL + string to interpret, and the second items is the template name used + after the <code class="inline-code">"->"</code>.</p> + + <p>The configuration settings that affect the interpreted + template are the same as of the surrounding template, except that + parser settings specified in the <a href="ref_directive_ftl.html#ref.directive.ftl"><code>ftl</code> directive</a> + or was established via tag syntax or naming convention + auto-detection are instead coming from the + <code class="inline-code">Configuration</code> object (or naturally, from the + <a href="pgui_config_templateconfigurations.html"><code>TemplateConfiguration</code></a>, + if there's any). Thus the tag syntax, naming convention, whitespace + handling, etc. of the interpreted template is independent of that + established <em>inside</em> the surrounding template. An + important exception from this rule is that the <a href="dgui_misc_autoescaping.html#dgui_misc_autoescaping_outputformat">output format</a> + and auto-escaping policy is inherited from the lexical context where + <code class="inline-code">interpret</code> is called from. For example in a + template that has <code class="inline-code"><#ftl + output_format="XML"></code> header (or if you are inside a + <code class="inline-code"><#output_format + "XML"><em class="code-color">...</em></#output_format></code> + block), <code class="inline-code">interpret</code> calls in it will produce + directives with XML output format.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_isType">is_...</h2> + + + + + + + <p>These built-ins check the type of a variable, and returns + <code class="inline-code">true</code> or <code class="inline-code">false</code> depending on the + type. The list of + <code class="inline-code">is_<em class="code-color">...</em></code> + built-ins:</p> + + <div class="table-responsive"> + <table class="table"> + + <thead> + <tr> + <th>Built-in</th> + + + <th>Returns <code class="inline-code">true</code> if the value is a ...</th> + + </tr> + + </thead> + + + <tbody> + <tr> + <td><code class="inline-code">is_string</code></td> + + + <td>string</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_number</code></td> + + + <td>number</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_boolean</code></td> + + + <td>boolean</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_date</code></td> + + + <td>Don't use it! Same as <code class="inline-code">is_date_like</code>, use + that instead. Later may changes meaning to + <code class="inline-code">date_only</code>.</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_date_like</code></td> + + + <td>date-like, means either date, time or date-time, or + date-like with unknown precise type (since FreeMarker + 2.3.21)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_date_only</code></td> + + + <td>date (no time of the day part) (since FreeMarker + 2.3.21)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_time</code></td> + + + <td>time (no year-month-day part) (since FreeMarker + 2.3.21)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_datetime</code></td> + + + <td>date-time (contains both year-month-day and time of the + day)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_unknown_date_like</code></td> + + + <td>date-like where we don't know if it's a date or a time or + a date-time</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_method</code></td> + + + <td>method</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_transform</code></td> + + + <td>transform</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_macro</code></td> + + + <td>macro or function (yes, also for function; a historical + glitch)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_hash</code></td> + + + <td>hash (including extended hash)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_hash_ex</code></td> + + + <td>extended hash (supports <code class="inline-code">?keys</code> and + <code class="inline-code">?values</code>)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_sequence</code></td> + + + <td>sequence (Historical quirk: Before <a href="pgui_config_incompatible_improvements.html#pgui_config_incompatible_improvements_how_to_set"><code>incompatible_improvements</code></a> + 2.3.24 it returns <code class="inline-code">true</code> for Java methods as + they implement the + <code class="inline-code">[<em class="code-color">index</em>]</code> + operator, however, they fail on + <code class="inline-code">?size</code>.)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_collection</code></td> + + + <td>collection (including extended collection)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_collection_ex</code></td> + + + <td>extended collection (supports + <code class="inline-code">?size</code>)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_enumerable</code></td> + + + <td>sequence or collection</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_indexable</code></td> + + + <td>sequence (Historical quirk: it returns + <code class="inline-code">true</code> for Java methods as they implement the + <code class="inline-code">[<em class="code-color">index</em>]</code> + operator.)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_directive</code></td> + + + <td>Whatever kind of directive (for example a macro, <span class="marked-for-programmers">or + <code class="inline-code">TemplateDirectiveModel</code>, + <code class="inline-code">TemplateTransformModel</code>, etc.</span>), or + function (a historical glitch)</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_node</code></td> + + + <td>node</td> + + </tr> + + + <tr> + <td><code class="inline-code">is_markup_output</code></td> + + + <td>markup output (a value that won't be <a href="dgui_misc_autoescaping.html">auto-escaped</a>)</td> + + </tr> + + </tbody> + + </table> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_markup_string">markup_string</h2> + + + <p></p> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.24.</p> + </div> + + + <p>Returns the markup stored inside a <a href="dgui_misc_autoescaping.html#dgui_misc_autoescaping_movalues">markup output value</a> + as string. This is useful if the value has to be passed to a Java + method for a <code class="inline-code">String</code> parameter, or if we want to + manipulate the markup directly in the template. Note that the + resulting string can be converted back to markup output value with + <a href="ref_builtins_string.html#ref_builtin_no_esc"><code>?no_esc</code></a>.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_namespace">namespace</h2> + + + + + <p>This built-in returns the namespace (i.e. the + "gate" hash to the namespace) associated with a macro + or function variable. You can use it with macros and functions + only.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_new">new</h2> + + + + + + + <p>This is to create a variable of a certain + <code class="inline-code">TemplateModel</code> implementation.</p> + + <p>On the left side of <code class="inline-code">?</code> you specify a string, + the full-qualified class name of a <code class="inline-code">TemplateModel</code> + implementation. The result is a method variable that calls the + constructor, and returns the new variable.</p> + + <p>Example:</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#-- Creates an user-defined directive be calling the parameterless constructor of the class --> +<#assign word_wrapp = "com.acmee.freemarker.WordWrapperDirective"?new()> +<#-- Creates an user-defined directive be calling the constructor with one numerical argument --> +<#assign word_wrapp_narrow = "com.acmee.freemarker.WordWrapperDirective"?new(40)></pre></div> + + <p>For more information about how the constructor parameters are + unwrapped and how overloaded constructor is chosen, read: <a href="pgui_misc_beanwrapper.html">Programmer's Guide/Miscellaneous/Bean wrapper</a></p> + + <p>This built-in can be a security concern because the template + author can create arbitrary Java objects and then use them, as far + as they implement <code class="inline-code">TemplateModel</code>. Also the + template author can trigger static initialization for classes that + don't even implement <code class="inline-code">TemplateModel</code>. You can + (since 2.3.17) restrict the classes accessible with this built-in + using + <code class="inline-code">Configuration.setNewBuiltinClassResolver(TemplateClassResolver)</code> + or the <code class="inline-code">new_builtin_class_resolver</code> setting. See + the Java API docs for more information. If you are allowing + not-so-much-trusted users to upload templates then you should + definitely look into this topic.</p> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_numToDate">number_to_date, number_to_time, number_to_datetime</h2> + + + + + + + + + + + + + + + + + <p>These are used to convert a number (usually a Java + <code class="inline-code">long</code>) to a date, time or date-time, respectively. + This does them same as <code class="inline-code">new java.util.Date(long)</code> + in Java, that is, the number is interpreted as the milliseconds + passed since the epoch. The number can be anything and of any type + as far as its value fits into a <code class="inline-code">long</code>. If the + number isn't a whole number, it will be rounded to whole with + half-up rule.</p> + + <p>Example:</p> + + + +<div class="code-wrapper"><pre class="code-block code-template">${1305575275540?number_to_datetime} +${1305575275540?number_to_date} +${1305575275540?number_to_time}</pre></div> + + <p>The output will be something like this (depending on the + current locale and time zone):</p> + + + +<div class="code-wrapper"><pre class="code-block code-output">May 16, 2011 3:47:55 PM +May 16, 2011 +3:47:55 PM</pre></div> + <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_builtins_type_independent.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_directives.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/ref_builtins_hash.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/ref_builtins_hash.html b/builds/2.3.26-nightly/ref_builtins_hash.html new file mode 100644 index 0000000..07e1ad3 --- /dev/null +++ b/builds/2.3.26-nightly/ref_builtins_hash.html @@ -0,0 +1,142 @@ +<!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>Built-ins for hashes - 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="Built-ins for hashes"> +<meta property="og:locale" content="en_US"> +<meta property="og:url" content="http://freemarker.org/docs/ref_builtins_hash.html"> +<link rel="canonical" href="http://freemarker.org/docs/ref_builtins_hash.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="ref.html"><span itemprop="name">Template Language Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins.html"><span itemprop="name">Built-in Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins_hash.html"><span itemprop="name">Built-ins for hashes</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 Language Reference","Built-in Reference","Built-ins for hashes"];</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="ref_builtins_sequence.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_node.html"><span>Next</span></a></div><div class="title-wrapper"> +<h1 class="content-header header-section1" id="ref_builtins_hash" itemprop="headline">Built-ins for hashes</h1> +</div></div><div class="page-menu"> +<div class="page-menu-title">Page Contents</div> +<ul><li><a class="page-menu-link" href="#ref_builtin_keys" data-menu-target="ref_builtin_keys">keys</a></li><li><a class="page-menu-link" href="#ref_builtin_values" data-menu-target="ref_builtin_values">values</a></li></ul> </div> + + + + +<h2 class="content-header header-section2" id="ref_builtin_keys">keys</h2> + + + + + <p>A sequence that contains all the lookup keys in the + hash.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#assign myHash = { "name": "mouse", "price": 50 }> +<#list myHash?keys as k> + ${k} +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> name + price</pre></div> + + <p>Note that not all hashes support this (ask the programmer if a + certain hash allows this or not).</p> + + <p>Since hashes do not define an order for their sub variables in + general, the order in which key names are returned can be arbitrary. + However, some hashes maintain a meaningful order (ask the programmer + if a certain hash does that or not). For example, hashes created + with the above <code class="inline-code">{<em class="code-color">...</em>}</code> + syntax preserve the same order as you have specified the sub + variables.</p> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>To list both the keys and the values, you can use + <code class="inline-code"><#list attrs as key, + value>...<#list></code>; see the <a href="ref_directive_list.html#ref.directive.list"><code>list</code> + directive</a>.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_values">values</h2> + + + + + <p>A sequence that contains all the variables (the values in the + key-value pairs) in the hash.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#assign myHash = { "name": "mouse", "price": 50 }> +<#list myHash?values as v> + ${v} +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> mouse + 50</pre></div> + + <p>Note that not all hashes support this (ask the programmer if a + certain hash allows this or not).</p> + + <p>As of the order in which the values are returned, the same + applies as with the <code class="inline-code">keys</code> built-in; see there. + Furthermore, it's not guaranteed that the order of the values + corresponds to the order of the keys returned by the + <code class="inline-code">keys</code> build-in.</p> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>To list both the keys and the values, you can use + <code class="inline-code"><#list attrs as key, + value>...<#list></code>; see the <a href="ref_directive_list.html#ref.directive.list"><code>list</code> + directive</a>.</p> + </div> + + <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_builtins_sequence.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_node.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/ref_builtins_loop_var.html ---------------------------------------------------------------------- diff --git a/builds/2.3.26-nightly/ref_builtins_loop_var.html b/builds/2.3.26-nightly/ref_builtins_loop_var.html new file mode 100644 index 0000000..6511bf8 --- /dev/null +++ b/builds/2.3.26-nightly/ref_builtins_loop_var.html @@ -0,0 +1,526 @@ +<!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>Loop variable built-ins - 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="Loop variable built-ins"> +<meta property="og:locale" content="en_US"> +<meta property="og:url" content="http://freemarker.org/docs/ref_builtins_loop_var.html"> +<link rel="canonical" href="http://freemarker.org/docs/ref_builtins_loop_var.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="ref.html"><span itemprop="name">Template Language Reference</span></a></li><li class="step-2" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins.html"><span itemprop="name">Built-in Reference</span></a></li><li class="step-3" itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem"><a class="label" itemprop="item" href="ref_builtins_loop_var.html"><span itemprop="name">Loop variable built-ins</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 Language Reference","Built-in Reference","Loop variable built-ins"];</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="ref_builtins_node.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_type_independent.html"><span>Next</span></a></div><div class="title-wrapper"> +<h1 class="content-header header-section1" id="ref_builtins_loop_var" itemprop="headline">Loop variable built-ins</h1> +</div></div><div class="page-menu"> +<div class="page-menu-title">Page Contents</div> +<ul><li><a class="page-menu-link" href="#ref_builtin_counter" data-menu-target="ref_builtin_counter">counter</a></li><li><a class="page-menu-link" href="#ref_builtin_has_next" data-menu-target="ref_builtin_has_next">has_next</a></li><li><a class="page-menu-link" href="#ref_builtin_index" data-menu-target="ref_builtin_index">index</a></li><li><a class="page-menu-link" href="#ref_builtin_is_even_item" data-menu-target="ref_builtin_is_even_item">is_even_item</a></li><li><a class="page-menu-link" href="#ref_builtin_is_first" data-menu-target="ref_builtin_is_first">is_first</a></li><li><a class="page-menu-link" href="#ref_builtin_is_last" data-menu-target="ref_builtin_is_last">is_last</a></li><li><a class="page-menu-link" href="#ref_builtin_is_odd_item" data-menu-target="ref_builtin_is_odd_item">is_odd_item</a></li><li><a class="page-menu-link" href="#ref_builtin_item_cycle" data-menu-target="ref_builtin_item_cycle">item_cycle</a></li><li><a class="page-menu-link" href="#ref_builtin_item _parity" data-menu-target="ref_builtin_item_parity">item_parity</a></li><li><a class="page-menu-link" href="#ref_builtin_item_parity_cap" data-menu-target="ref_builtin_item_parity_cap">item_parity_cap</a></li></ul> </div> <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>Loop variable built-ins only exists since FreeMarker + 2.3.23.</p> + </div> +<p>These built-ins you can only use with the loop variable of the + <a href="ref_directive_list.html"><code>list</code> and + <code>items</code> directives</a> (and of the deprecated + <code class="inline-code">foreach</code> directive). Some explanation of that + follows (<code class="inline-code"><em class="code-color">loopVar</em>?index</code> + returns the 0-based index in the listable value we iterate + through):</p> + +<div class="code-wrapper"><pre class="code-block code-template"><#-- Note: x is a loop variable --> +<#list ['a', 'b', 'c'] as x> + ${x?index} +</#list></pre></div> + +<div class="code-wrapper"><pre class="code-block code-output">0 +1 +2</pre></div><p>When the <code class="inline-code">list</code> directive doesn't specify the + loop variable, these built-ins are used with the loop variable of the + <code class="inline-code">items</code> directive:</p> + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c']> + <ul> + <#items as x> + <li>${x?index}</li> + </#items> + </ul> +</#list></pre></div><p>Loop variable built-ins only use the <em>name</em> + of loop variable, so that they can identify the related ongoing + iteration. They don't read the <em>value</em> of the loop + variable. Hence, this is a parsing error:</p> + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as x> + <#assign y = x> + ${y?index} <#-- ERROR: y isn't a loop variable --> +</#list></pre></div> + + + + +<h2 class="content-header header-section2" id="ref_builtin_counter">counter</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Returns the 1-based index where the iteration (which is + identified by the loop variable name) currently stands.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as i> + ${i?counter}: ${i} +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> 1: a + 2: b + 3: c</pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>For the 0-based index, use the <a href="#ref_builtin_index"><code>index</code> + built-in</a>.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_has_next">has_next</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Tells if the item where the iteration (which is identified by + the loop variable name) currently stands is not the last + item.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as i>${i?has_next?c} </#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output">true true false </pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>For separating items with commas and such, use + <code class="inline-code"><#sep><em class="code-color">separator</em></#sep></code> + instead of <code class="inline-code"><#if + <em class="code-color">var</em>?has_next><em class="code-color">separator</em></#if></code>, + as it's more readable. (Furthermore the + <code class="inline-code"></#sep></code> can be often omitted, like in + <code class="inline-code"><#list <em class="code-color">...</em> as + <em class="code-color">var</em>><em class="code-color">...</em>${<em class="code-color">var</em>}<em class="code-color">...</em><#sep><em class="code-color">separator</em></#list></code>)</p> + </div> + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>If you need the inverse of this built-in, use + <code class="inline-code"><em class="code-color">var</em>?is_last</code> instead + of <code class="inline-code">!<em class="code-color">var</em>?has_next</code>, + because it's more readable.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_index">index</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Returns the 0-based index where the iteration (which is + identified by the loop variable name) currently stands.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as i> + ${i?index}: ${i} +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> 0: a + 1: b + 2: c</pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>For the 1-based index, use the <a href="#ref_builtin_counter"><code>counter</code> + built-in</a>.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_is_even_item">is_even_item</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Tells if the item where the iteration (which is identified by + the loop variable name) currently stands has an even 1-based + index.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c', 'd'] as i>${i?is_even_item?c} </#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output">false true false true</pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>To make tables with alternating row colors and such, use + <a href="#ref_builtin_item_parity"><code><em>var</em>?item_parity</code></a> + or <a href="#ref_builtin_item_cycle"><code><em>var</em>?item_cycle(...)</code></a> + instead.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_is_first">is_first</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Tells if the item where the iteration (which is identified by + the loop variable name) currently stands is the first item.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as i>${i?is_first?c} </#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output">true false false </pre></div> + + + + + +<h2 class="content-header header-section2" id="ref_builtin_is_last">is_last</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Tells if the item where the iteration (which is identified by + the loop variable name) currently stands is the last item.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c'] as i>${i?is_last?c} </#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output">false false true</pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>If you need the inverse of this built-in, use + <code class="inline-code"><em class="code-color">var</em>?has_next</code> instead + of <code class="inline-code">!<em class="code-color">var</em>?is_last</code>, + because it's more readable.</p> + </div> + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>For separating items with commas and such, use + <code class="inline-code"><#sep><em class="code-color">separator</em></#sep></code> + instead of <code class="inline-code"><#if + <em class="code-color">var</em>?has_next><em class="code-color">separator</em></#if></code>, + as it's more readable. (Furthermore the + <code class="inline-code"></#sep></code> can be often omitted, like in + <code class="inline-code"><#list <em class="code-color">...</em> as + <em class="code-color">var</em>><em class="code-color">...</em>${<em class="code-color">var</em>}<em class="code-color">...</em><#sep><em class="code-color">separator</em></#list></code>)</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_is_odd_item">is_odd_item</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Tells if the item where the iteration (which is identified by + the loop variable name) currently stands has an odd 1-based + index.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c', 'd'] as i>${i?is_odd_item?c} </#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output">true false true false </pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>To make tables with alternating row colors and such, use + <a href="#ref_builtin_item_parity"><code><em>var</em>?item_parity</code></a> + or <a href="#ref_builtin_item_cycle"><code><em>var</em>?item_cycle(...)</code></a> + instead.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_item_cycle">item_cycle</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>This is a more generic version of the <a href="#ref_builtin_item_parity"><code>item_parity</code> + built-in</a>, where you can specify what value to use instead of + <code class="inline-code">"odd"</code> and <code class="inline-code">"even"</code>. It also + allows more than 2 values that it will cycle through.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c', 'd', 'e', 'f', 'g'] as i> + <tr class="${i?item_cycle('row1', 'row2', 'row3')}">${i}</tr> +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> <tr class="row1">a</tr> + <tr class="row2">b</tr> + <tr class="row3">c</tr> + <tr class="row1">d</tr> + <tr class="row2">e</tr> + <tr class="row3">f</tr> + <tr class="row1">g</tr></pre></div> + + <p>Some details:</p> + + <ul> + <li> + <p>The number of arguments must be at least 1, and has no + upper limit.</p> + </li> + + <li> + <p>The type of the arguments can be anything, they doesn't + have to be strings.</p> + </li> + </ul> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>Use the <a href="#ref_builtin_item_parity"><code>item_parity</code> + built-in</a> instead if the values you need are + <code class="inline-code">"odd"</code> and <code class="inline-code">"even"</code>.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_item_parity">item_parity</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Returns <code class="inline-code">"odd"</code> or <code class="inline-code">"even"</code> + string value, depending on the parity of the 1-based index where the + iteration (which is identified by the loop variable name) currently + stands. This is commonly used for alternating color for table + rows:</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c', 'd'] as i> + <tr class="${i?item_parity}Row">${i}</tr> +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> <tr class="oddRow">a</tr> + <tr class="evenRow">b</tr> + <tr class="oddRow">c</tr> + <tr class="evenRow">d</tr></pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>Use the <a href="#ref_builtin_item_parity"><code>item_parity_cap</code> + built-in</a> for capitalized <code class="inline-code">"Odd"</code> and + <code class="inline-code">"Even"</code>. Use the <a href="#ref_builtin_item_cycle"><code>item_cycle</code> + built-in</a> to specify custom values, or more then two + values.</p> + </div> + + + + + + +<h2 class="content-header header-section2" id="ref_builtin_item_parity_cap">item_parity_cap</h2> + + + + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>This built-in is available since FreeMarker 2.3.23.</p> + </div> + + + <p>Returns <code class="inline-code">"Odd"</code> or <code class="inline-code">"Even"</code> + string value (note the capitalization), depending on the parity of + the 1-based index where the iteration (which is identified by the + loop variable name) currently stands.</p> + + + +<div class="code-wrapper"><pre class="code-block code-template"><#list ['a', 'b', 'c', 'd'] as i> + <tr class="row${i?item_parity_cap}">${i}</tr> +</#list></pre></div> + + + +<div class="code-wrapper"><pre class="code-block code-output"> <tr class="rowOdd">a</tr> + <tr class="rowEven">b</tr> + <tr class="rowOdd">c</tr> + <tr class="rowEven">d</tr></pre></div> + + <div class="callout note"> + <strong class="callout-label">Note:</strong> + + <p>Use the <a href="#ref_builtin_item_parity"><code>item_parity</code> + built-in</a> for lower case <code class="inline-code">"odd"</code> and + <code class="inline-code">"even"</code>.</p> + </div> + + <div class="bottom-pagers-wrapper"><div class="pagers bottom"><a class="paging-arrow previous" href="ref_builtins_node.html"><span>Previous</span></a><a class="paging-arrow next" href="ref_builtins_type_independent.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>
