Interface TemplateModel

All Known Subinterfaces:
AdapterTemplateModel, MethodCallAwareTemplateHashModel, TemplateBooleanModel, TemplateCollectionModel, TemplateCollectionModelEx, TemplateDateModel, TemplateDirectiveModel, TemplateHashModel, TemplateHashModelEx, TemplateHashModelEx2, TemplateMarkupOutputModel<MO>, TemplateMethodModel, TemplateMethodModelEx, TemplateModelWithAPISupport, TemplateNodeModel, TemplateNodeModelEx, TemplateNumberModel, TemplateScalarModel, TemplateSequenceModel, TemplateTransformModel, WrapperTemplateModel
All Known Implementing Classes:
AllHttpScopesHashModel, AllHttpScopesHashModel, ArrayModel, BeanModel, BooleanModel, CaptureOutput, CollectionModel, CommonTemplateMarkupOutputModel, DateModel, DefaultArrayAdapter, DefaultEnumerationAdapter, DefaultIterableAdapter, DefaultIteratorAdapter, DefaultListAdapter, DefaultMapAdapter, DefaultNonListCollectionAdapter, DOMNodeModel, EnumerationModel, Environment.Namespace, Execute, GenericObjectModel, HtmlEscape, HttpRequestHashModel, HttpRequestHashModel, HttpRequestParametersHashModel, HttpRequestParametersHashModel, HttpSessionHashModel, HttpSessionHashModel, IncludePage, IncludePage, IteratorModel, JythonHashModel, JythonModel, JythonNumberModel, JythonRuntime, JythonSequenceModel, LocalizedString, MapModel, NodeListModel, NodeListModel, NodeModel, NormalizeNewlines, NumberModel, ObjectConstructor, OverloadedMethodsModel, ResourceBundleLocalizedString, ResourceBundleModel, RhinoFunctionModel, RhinoScriptableModel, ServletContextHashModel, ServletContextHashModel, SimpleCollection, SimpleDate, SimpleHash, SimpleList, SimpleMapModel, SimpleMethodModel, SimpleNumber, SimpleScalar, SimpleSequence, StandardCompress, StringModel, TaglibFactory, TaglibFactory, TemplateCombinedMarkupOutputModel, TemplateHTMLOutputModel, TemplateModelListSequence, TemplateRTFOutputModel, TemplateXHTMLOutputModel, TemplateXMLOutputModel, XmlEscape

public interface TemplateModel
The common super-interface of the interfaces that stand for the FreeMarker Template Language (FTL) data types. The template language only deals with TemplateModel-s, not directly with plain Java objects. (For example, it doesn't understand Number, but TemplateNumberModel.) This is why the data-model (aka. the "template context" in other languages) is (automatically) mapped to a tree of TemplateModel-s.

Mapping the plain Java objects to TemplateModel-s (or the other way around sometimes) is the responsibility of the ObjectWrapper (can be set via Configuration.setObjectWrapper(ObjectWrapper)). But not all TemplateModel-s are for wrapping a plain object. For example, a value created within a template is not made to wrap an earlier existing object; it's a value that has always existed in the template language's domain. Users can also write TemplateModel implementations and put them directly into the data-model for full control over how that object is seen from the template. Certain TemplateModel interfaces doesn't even have equivalent in Java. For example the directive type (TemplateDirectiveModel) is like that.

Because TemplateModel "subclasses" are all interfaces, a value in the template language can have multiple types. However, to prevent ambiguous situations, it's not recommended to make values that implement more than one of these types: string, number, boolean, date. The intended applications are like string+hash, string+method, hash+sequence, etc.

See Also:
ClassUtil.getFTLTypeDescription(TemplateModel)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    A general-purpose object to represent nothing.
  • Field Details

    • NOTHING

      static final TemplateModel NOTHING
      A general-purpose object to represent nothing. It acts as an empty string, false, empty sequence, empty hash, and null-returning method model.