Each node in the data model tree must implement one of the subinterfaces of
TemplateModel. The root node must implement TemplateModelRoot. The
other nodes must implement TemplateHashModel, TemplateListModel,
TemplateScalarModel, or TemplateMethodModel.
Scalars are the most simple of the TemplateModels. A scalar
model simply returns a single value as a String.
The one method that TemplateScalarModel declares is:
public java.lang.String getAsString()
throws TemplateModelException;
All of the TemplateModels can throw TemplateModelExceptions. Normally when a TemplateModelException
is thrown, FreeMarker will embed the error message in the output, inside an
HTML comment.
All TemplateModels also declare the isEmpty() method. If
the TemplateModel is empty, for instance, when a list contains
no values, or a scalar has no value, this method should return false. This
is used primarily for FreeMarker to check for boolean values.
If for some reason you need to return a boolean "false" value or an
empty string, getAsString() can safely return a null
value.
| Previous: Turning Off Parsing | Next: List Models |