freemarker.apache.org
Open in
urlscan Pro
2a04:4e42::644
Public Scan
URL:
https://freemarker.apache.org/docs/ref_directive_if.html
Submission: On December 13 via api from US — Scanned from DE
Submission: On December 13 via api from US — Scanned from DE
Form analysis
1 forms found in the DOMGET search-results.html
<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="search-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>
Text Content
Unsupported web browser - Use a modern browser to view this website! * Home * Manual * Java API * Contribute * Report a Bug * Download Manual Search formSearch querySearch * Apache FreeMarker Manual * Template Language Reference * Directive Reference * if, else, elseif Bookmarks: * Alpha. index * Glossary * Expressions * ?builtins * #directives * .spec_vars * FAQ * Template Author's Guide * Getting Started * Template + data-model = output * The data-model at a glance * The template at a glance * Values, Types * Basics * The types * The Template * Overall structure * Directives * Expressions * Interpolations * Miscellaneous * Defining your own directives * Defining variables in the template * Namespaces * Auto-escaping and output formats * Formatting for humans, or for computers * White-space handling * Alternative (square bracket) syntax * Programmer's Guide * Getting Started * Create a configuration instance * Create a data-model * Get the template * Merging the template with the data-model * Putting all together * The Data Model * Basics * Scalars * Containers * Methods * Directives * Node variables * Object wrappers * The Configuration * Basics * Shared variables * Settings * Template loading * Error handling * Template configurations * Associating output formats with templates * Custom number and date/time formats * The "incompatible improvements" setting * Miscellaneous * Variables, scopes * Charset issues * Multithreading * Bean wrapper * Logging * Using FreeMarker with servlets * Configuring security policy for FreeMarker * Legacy XML wrapper implementation * Using FreeMarker with Ant * Jython wrapper * Template Language Reference * Built-in Reference * Alphabetical index * Built-ins for strings * Built-ins for numbers * Built-ins for date/time/date-time values * Built-ins for booleans * Built-ins for sequences * Built-ins for hashes * Built-ins for nodes (for XML) * Loop variable built-ins * Type independent built-ins * Seldom used and expert built-ins * Directive Reference * Alphabetical index * assign * attempt, recover * autoesc * compress * escape, noescape (deprecated) * flush * ftl * function, return * global * if, else, elseif * import * include * list, else, items, sep, break, continue * local * macro, nested, return * noautoesc * noparse * nt * outputformat * setting * stop * switch, case, default, break * t, lt, rt * User-defined directive (<@...>) * visit, recurse, fallback * Special Variable Reference * Reserved names in FTL * Deprecated FTL constructs * List of deprecated directives * List of deprecated built-ins * Old-style macro and call directives * Transform directive * Old FTL syntax * #{...}: Numerical interpolation * XML Processing Guide * Preface * Exposing XML documents * The DOM tree * Putting the XML into the data-model * Imperative XML processing * Basics * Details * Declarative XML processing * Basics * Details * Appendixes * FAQ * Version history * 2.3.32 * 2.3.31 * 2.3.30 * 2.3.29 * 2.3.28 * 2.3.27 (incubating at Apache) * 2.3.26 (incubating at Apache) * 2.3.25 (incubating at Apache) * 2.3.24 (incubating at Apache) * 2.3.23 * 2.3.22 * 2.3.21 * 2.3.20 * 2.3.19 * 2.3.18 * 2.3.17 * 2.3.16 * 2.3.15 * 2.3.14 * 2.3.13 * 2.3.12 * 2.3.11 * 2.3.10 * 2.3.9 * 2.3.8 * 2.3.7 * 2.3.7 RC1 * 2.3.6 * 2.3.5 * 2.3.4 * 2.3.3 * 2.3.2 * 2.3.1 * 2.3 * 2.2.8 * 2.2.7 * 2.2.6 * 2.2.5 * 2.2.4 * 2.2.3 * 2.2.2 * 2.2.1 * 2.2 * 2.1.5 * 2.1.4 * 2.1.3 * 2.1.2 * 2.1.1 * 2.1 * 2.01 * 2.0 * 2.0 RC3 * 2.0 RC2 * 2.0 RC1 * Installing FreeMarker * Legal * License * Export Control * Glossary * Alphabetical Index PreviousNext IF, ELSE, ELSEIF Page Contents * Synopsis * Description SYNOPSIS <#if condition> ... <#elseif condition2> ... <#elseif condition3> ... ... <#else> ... </#if> Where: * condition, condition2, ...etc.: Expression evaluates to a boolean value. The elseif-s and the else are optional. Camel case name variant: elseIf DESCRIPTION You can use if, elseif and else directives to conditionally skip a section of the template. The condition-s must evaluate to a boolean value, or else an error will abort template processing. The elseif-s and else-s must occur inside if (that is, between the if start-tag and end-tag). The if can contain any number of elseif-s (including 0) and at the end optionally one else. Examples: if with 0 elseif and no else: Template <#if x == 1> x is 1 </#if> if with 0 elseif and else: Template <#if x == 1> x is 1 <#else> x is not 1 </#if> if with 2 elseif and no else: Template <#if x == 1> x is 1 <#elseif x == 2> x is 2 <#elseif x == 3> x is 3 </#if> if with 3 elseif and else: Template <#if x == 1> x is 1 <#elseif x == 2> x is 2 <#elseif x == 3> x is 3 <#elseif x == 4> x is 4 <#else> x is not 1 nor 2 nor 3 nor 4 </#if> To see more about boolean expressions, see: Template Author's Guide/The Template/Expressions. You can nest if directives (of course): Template <#if x == 1> x is 1 <#if y == 1> and y is 1 too <#else> but y is not </#if> <#else> x is not 1 <#if y < 0> and y is less than 0 </#if> </#if> Note: When you want to test if x > 0 or x >= 0, writing <#if x > 0> and <#if x >= 0> is WRONG, as the first > will close the #if tag. To work that around, write <#if x gt 0> or <#if gte 0>. Also note that if the comparison occurs inside parentheses, you will have no such problem, like <#if foo.bar(x > 0)> works as expected. PreviousNext OVERVIEW * What is FreeMarker? * Download * Version history * FAQ * License * Privacy policy OFTEN USED / REFERENCE * Try template online * Expressions cheatsheet * #directives * ?built_ins * .special_vars * Configuration settings COMMUNITY * Github project page * Report a bug * Report security vulnerability * Get help on StackOverflow * Announcements on Twitter * Discuss on mailing lists * Github * Twitter * Stack Overflow Edited with XMLMind XML Editor Last generated: 2023-05-11 21:11:51 GMT, for Freemarker 2.3.32 © 1999–2023 The Apache Software Foundation. Apache FreeMarker, FreeMarker, Apache Incubator, Apache, the Apache FreeMarker logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.