Data Models

Method Model

The TemplateMethodModel interface defines FreeMarker's way of implementing methods within a TemplateModel. The signature of a TemplateMethodModel is below:

public TemplateModel exec(java.util.List arguments)
                   throws TemplateModelException;

The argument list that FreeMarker supplies is a list of String objects, each one corresponding with an argument supplied to the method, in the order that they were specified. If a method is called with no arguments, the list will be empty, rather than null.

Note: Unlike other languages, such as Perl, FreeMarker does not flatten complex variables. If a TemplateListModel or TemplateHashModel is passed as a parameter to a TemplateMethodModel FreeMarker will issue an error message.

Like most other models, TemplateMethodModel returns a TemplateModel. This allows method calls to be very flexible, and allows methods to be chained together similarly to the way other TemplateModels can be chained.

Note that TemplateMethodModel implements a call to only one method. To provide many methods, wrap up lots of TemplateMethodModels inside a TemplateHashModel, one for each method you want to provide.