Settings

Settings are named values that influence the behavior of FreeMarker. Examples of settings are: locale, number_format

Settings stored in Configuration instance can be overridden in a Template instance. For example you set "en_US" for the locale setting in the configuration, then the locale in all templates that use this configuration will be "en_US", except in templates where the locale was explicitly specified differently (see localization). Thus, values in a Configuration serve as defaults that can be overridden in a per template manner. The value comes from Configuration instance or Template instance can be further overridden for a single Template.process call. For each such call a freemarker.core.Environment object is created internally that holds the runtime environment of the template processing, including the setting values that were overridden on that level. The values stored there can even be changed during the template processing, so a template can set settings itself, like switching locale at the middle of the output.

This can be imagined as 3 layers (Configuration, Template, Environment) of settings, where the topmost layer that contains the value for a certain setting provides the effective value of that setting. For example (settings A to F are just imaginary settings for this example):

Setting A Setting B Setting C Setting D Setting E Setting F
Layer 3: Environment 1 - - 1 - -
Layer 2: Template 2 2 - - 2 -
Layer 1: Configuration 3 3 3 3 - -

The effective value of settings will be: A = 1, B = 2, C = 3, D = 1, E = 2. The F setting is probably null, or it throws exception when you try to get it.

Let's see exactly how to set settings:

To see the list of supported settings and their meaning, please read the following parts of the FreeMarker Java API documentation:

FreeMarker Manual -- For FreeMarker 2.3.22
HTML generated: 2015-02-28 21:34:03 GMT
Edited with XMLMind XML Editor
Here!