Package freemarker.template
Interface TemplateDirectiveModel
- All Superinterfaces:
TemplateModel
- All Known Implementing Classes:
IncludePage
,IncludePage
"directive" template language data type: used as user-defined directives
(much like macros) in templates. They can do arbitrary actions, write arbitrary
text to the template output, and trigger rendering of their nested content for
any number of times.
They are used in templates like <@myDirective foo=1 bar="wombat">...</@myDirective>
(or as
<@myDirective foo=1 bar="wombat" />
- the nested content is optional).
- Since:
- 2.3.11
-
Field Summary
Fields inherited from interface freemarker.template.TemplateModel
NOTHING
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
Executes this user-defined directive; called by FreeMarker when the user-defined directive is called in the template.
-
Method Details
-
execute
void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOExceptionExecutes this user-defined directive; called by FreeMarker when the user-defined directive is called in the template.This method should not throw
RuntimeException
, norIOException
that wasn't caused by writing to the output. Such exceptions should be catched inside the method and wrapped inside aTemplateException
. (Note that settingConfiguration.setWrapUncheckedExceptions(boolean)
totrue
can mitigate the negative effects of implementations that throwRuntimeException
-s.)- Parameters:
env
- the current processing environment. Note that you can access the outputWriter
byEnvironment.getOut()
.params
- the parameters (if any) passed to the directive as a map of key/value pairs where the keys areString
-s and the values areTemplateModel
instances. This is nevernull
. If you need to convert the template models to POJOs, you can use the utility methods in theDeepUnwrap
class.loopVars
- an array that corresponds to the "loop variables", in the order as they appear in the directive call. ("Loop variables" are out-parameters that are available to the nested body of the directive; see in the Manual.) You set the loop variables by writing this array. The length of the array gives the number of loop-variables that the caller has specified. Nevernull
, but can be a zero-length array.body
- an object that can be used to render the nested content (body) of the directive call. If the directive call has no nested content (i.e., it's like <@myDirective /> or <@myDirective></@myDirective>), then this will benull
.- Throws:
TemplateException
- If any problem occurs that's not anIOException
during writing the template output.IOException
- When writing the template output fails. OtherIOException
-s should be catched in this method and wrapped intoTemplateException
.
-