Reserved Names in FreeMarker Template Language (FTL)

FreeMarker Template Language (FTL) is a powerful tool for creating dynamic web pages and emails, among other uses. However, like any programming or scripting language, it has certain reserved names that you need to be aware of. These names are keywords in FTL and cannot be used for top-level variables unless accessed using square-bracket syntax (e.g., .vars["in"]). Below, we’ll explore these reserved names and their significance.

Reserved Names in FTL

1. true

  • Description: Represents the boolean value “true”.
  • Usage: Typically used in conditional statements.
  • Example:
<#if condition == true>
    The condition is true.
</#if>

2. false

  • Description: Represents the boolean value “false”.
  • Usage: Typically used in conditional statements.
  • Example:
<#if condition == false>
    The condition is false.
</#if>

3. gt

  • Description: Comparison operator for “greater than”.
  • Usage: Used to compare numerical values.
  • Example:
<#if value1 gt value2>
    Value1 is greater than Value2.
</#if>

4. gte

  • Description: Comparison operator for “greater than or equivalent”.
  • Usage: Used to compare numerical values.
  • Example:
<#if value1 gte value2>
    Value1 is greater than or equal to Value2.
</#if>

5. lt

  • Description: Comparison operator for “less than”.
  • Usage: Used to compare numerical values.
  • Example:
<#if value1 lt value2>
    Value1 is less than Value2.
</#if>

6. lte

  • Description: Comparison operator for “less than or equivalent”.
  • Usage: Used to compare numerical values.
  • Example:
<#if value1 lte value2>
    Value1 is less than or equal to Value2.
</#if>

7. as

  • Description: Used by a few directives in FTL.
  • Usage: Typically found in complex directives for assigning values.
  • Example:
<#assign user as newUser>

8. in

  • Description: Used by a few directives in FTL.
  • Usage: Commonly found in loop constructs.
  • Example:
<#list users as user>
    ${user.name}
</#list>

9. using

  • Description: Used by a few directives in FTL.
  • Usage: Typically found in macro and function calls.
  • Example:
<#macro render user using options>
    ${user.name}
</#macro>

Leave a comment

Your email address will not be published. Required fields are marked *