Synopsis
<#outputformat formatName>
...
</#outputFormat>
Where:
-
formatName
: A string constant; can't contain runtime expressions! This is the name of the output format, like"HTML"
,"XML"
, etc.; see the table of the predefined output formats here. The referred output format must be known by theConfiguration
, or else a parse-time error will occur. The name can also be like"outerFormatName{innerFormatName}"
, or"{innerFormatName}"
; see combined output formats later.
Camel case name variant: outputFormat
outputformat
exists since FreeMarker
2.3.24.
Description
Sets the output format to the specified one, inside the nested block. At the end of the block, the earlier output format is restored.
This directive only has effect on the section that is literally (as in the text editor) inside the nested bock, not on the parts that are called/included from there.
Example:
<#ftl output_format="XML"> XML escaping: ${"&{}"} <#outputformat "RTF"> RTF escaping: ${"&{}"} </#outputformat> <#outputformat "plainText"> No escsaping: ${"&{}"} </#outputformat> XML escsaping: ${"&{}"}
XML escsaping: &{} RTF escaping: &\{\} No escsaping: &{} XML escsaping: &{}
Combined (nested) output formats
When outputformat
-s are nested into each
other, normally, only the innermost output format will count. For
example:
<#ftl output_format="XML"> ${"'{}"} <#outputformat "HTML"> ${"'{}"} <#outputformat "RTF"> ${"'{}"} </#outputformat> </#outputformat>
'{} '{} '\{\}
But sometimes you want all enclosing output format escaping
to be applied at once. In that case the 2nd
${...}
above should
be escaped with "HTML"
and then with
"XML"
, and the 3rd
${...}
should be
escaped with "RTF"
and then with
"HTML"
and then with "XML"
.
These are called combined output formats, and can be referred by
names like "XML{HTML}"
and
"XML{HTLM{RTF}}"
, respectively. We could use
these names in the earlier two outputformat
calls, however, there's a shorthand where you inherit the part
outside the {...}
from the enclosing output format:
<#ftl outputFormat="XML"> ${"'{}"} <#outputFormat "{HTML}"><#-- Same as "XML{HTML}" --> ${"'{}"} <#outputFormat '{RTF}'><#-- Same as "XML{HTML{RTF}}" --> ${"'{}"} </#outputFormat> </#outputFormat>
'{} &#39;{} &#39;\{\}