Chapter 4. Special Variable Reference
Special variables are variables defined by the FreeMarker engine itself. To access them, you use the .variable_name syntax. For example, you can't write simply version; you have to write .version.
The supported special variables are:
- vars: Expression .vars.foo returns the same variable as expression foo. 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 .vars["A strange name!"]. Or, to access a top-level variable with dynamic name given with variable varName you can write .vars[varName]. Note that the hash returned by .vars does not support ?keys and ?values.
- locals: A hash that you can use to access the local variables (the variables created with the local directive, and the parameters of macro).
- namespace: A hash that you can use to access the current namespace. Note that global variables like the variables of data-model are not visible through this hash.
- main: A hash that you can use to access the main namespace. Note that global variables like the variables of data-model are not visible through this hash.
- globals: A hash that you can use to access the globally accessible variables: the data-model and the variables created with global directive. Note that variables created with assign or macro are not globals, thus they never hide the variables when you use globals.
- data_model: A hash that you can use to access the data-model directly. That is, variables you did with global directive are not visible here.
- node (alias current_node for historical reasons): The node you are currently processing with the visitor pattern (i.e. with the visit, recurse, ...etc. directives). Also, it initially stores the root node when you use the FreeMarker XML Ant task.
- locale: Returns the current value of the locale setting. This is a string, for example en_US. For more information about locale strings see the setting directive.
- language: Returns the language part of the current value of the locale setting. For example if .locale is en_US, then .lang is en.
- version: Returns the FreeMarker version number as string, for example 2.2.8. 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. 2.3pre6), or abbrevation ``rc'' for ``release candidate''.
 |
|
 |