Uses of Interface
freemarker.template.TemplateModel
Packages that use TemplateModel
Package
Description
The seldom used or advanced parts of the fundamental FreeMarker API, compared to
freemarker.template.The default object wrapper of FreeMarker uses
this to expose Java Beans and POJO-s to templates.
Exposes DOM XML nodes to templates as easily traversable trees;
see in the Manual.
Deprecated, use W3C DOM (
freemarker.ext.dom) instead;
Exposes JDOM XML nodes to templates.
Classes for two-way FreeMarker-JSP integration.
Servlet for legacy "Model 2" frameworks that allows using FreeMarker
templates instead of JSP as the MVC View
(see in the Manual).
Various classes used by
freemarker.ext but might be useful outside it too.Deprecated, use W3C DOM with
freemarker.ext.dom instead;
Exposes XML from DOM, dom4j or JDOM nodes, uniformly.The fundamental, most commonly used API-s of FreeMarker;
start with
Configuration (see also the
Getting Started in the Manual.)Various classes used by core FreeMarker code but might be useful outside of it too.
-
Uses of TemplateModel in freemarker.core
Subinterfaces of TemplateModel in freemarker.coreModifier and TypeInterfaceDescriptioninterfaceTemplateMarkupOutputModel<MO extends TemplateMarkupOutputModel<MO>>"markup output" template language data-type; stores markup (some kind of "rich text" / structured format, as opposed to plain text) that meant to be printed as template output.Classes in freemarker.core that implement TemplateModelModifier and TypeClassDescriptionclassCommonTemplateMarkupOutputModel<MO extends CommonTemplateMarkupOutputModel<MO>>Common superclass for implementingTemplateMarkupOutputModel-s that belong to aCommonMarkupOutputFormatsubclass format.classfinal classStores combined markup to be printed; used withCombinedMarkupOutputFormat.classStores HTML markup to be printed; used withHTMLOutputFormat.classStores RTF markup to be printed; used withRTFOutputFormat.classStores HTML markup to be printed; used withHTMLOutputFormat.classStores XML markup to be printed; used withXMLOutputFormat.Methods in freemarker.core that return TemplateModelModifier and TypeMethodDescriptionEnvironment.getDataModelOrSharedVariable(String name) Returns the variable from the data-model, or if it's not there, then from the Configuration.setSharedVariables(Map) shared variables}Environment.getGlobalVariable(String name) Returns the globally visible variable of the given name, ornull.Environment.getLocalVariable(String name) Returns the loop or macro local variable corresponding to this variable name.Environment.getVariable(String name) Returns the variable that is visible in this context, ornullif the variable is not found.DefaultTruncateBuiltinAlgorithm.truncateCM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateCM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_c_m(...)in templates.DefaultTruncateBuiltinAlgorithm.truncateM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_m(...)in templates.DefaultTruncateBuiltinAlgorithm.truncateWM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateWM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_w_m(...)in templates.Methods in freemarker.core with parameters of type TemplateModelModifier and TypeMethodDescriptionbooleanEnvironment.applyEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL "==" operator.booleanEnvironment.applyEqualsOperatorLenient(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL "==" operator, except that if the two types are incompatible, they are treated as non-equal instead of throwing an exception.booleanEnvironment.applyGreaterThanOperator(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL ">" operator.booleanEnvironment.applyLessThanOperator(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL "<" operator.booleanEnvironment.applyLessThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL "<" operator.booleanEnvironment.applyWithGreaterThanOrEqualsOperator(TemplateModel leftValue, TemplateModel rightValue) Compares twoTemplateModel-s according the rules of the FTL ">=" operator.static booleanNonSequenceOrCollectionException.isWrappedIterable(TemplateModel model) voidEnvironment.setGlobalVariable(String name, TemplateModel value) Sets a variable in the global namespace, like<#global name=value>.voidEnvironment.setLocalVariable(String name, TemplateModel value) Sets a local variable that's on the top-level inside a macro or function invocation, like<#local name=value>.voidEnvironment.setVariable(String name, TemplateModel value) Sets a variable in the current namespace, like<#assign name=value>.DefaultTruncateBuiltinAlgorithm.truncateCM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateCM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_c_m(...)in templates.DefaultTruncateBuiltinAlgorithm.truncateM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_m(...)in templates.DefaultTruncateBuiltinAlgorithm.truncateWM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) abstract TemplateModelTruncateBuiltinAlgorithm.truncateWM(String s, int maxLength, TemplateModel terminator, Integer terminatorLength, Environment env) Corresponds to?truncate_w_m(...)in templates. -
Uses of TemplateModel in freemarker.ext.beans
Classes in freemarker.ext.beans that implement TemplateModelModifier and TypeClassDescriptionclassA class that will wrap an arbitrary array intoTemplateCollectionModelandTemplateSequenceModelinterfaces.classA class that will wrap an arbitrary object intoTemplateHashModelinterface allowing calls to arbitrary property getters and invocation of accessible methods on the object from a template using the object.foo to access properties and object.bar(arg1, arg2) to invoke methods on it.classA class that will wrap instances ofBooleaninto aTemplateBooleanModel.classA special case ofBeanModelthat can wrap Java collections and that implements theTemplateCollectionModelin order to be usable in a <#list> block.classWraps arbitrary subclass ofDateinto a reflective model.classA class that addsTemplateModelIteratorfunctionality to theEnumerationinterface implementers.classA class that addsTemplateModelIteratorfunctionality to theIteratorinterface implementers.classA special case ofBeanModelthat adds implementation forTemplateMethodModelExon map objects that is a shortcut for the Map.get() method.classWraps arbitrary subclass ofNumberinto a reflective model.classWraps a set of same-name overloaded methods behindTemplateMethodModelinterface, like if it was a single method, chooses among them behind the scenes on call-time based on the argument values.classA hash model that wraps a resource bundle.classModel used byBeansWrapperwhen simpleMapWrapper mode is enabled.final classA class that will wrap a reflected method call into aTemplateMethodModelinterface.classSubclass ofBeanModelthat exposes the return value of theObject.toString()method through theTemplateScalarModelinterface.Methods in freemarker.ext.beans that return TemplateModelModifier and TypeMethodDescriptionprotected TemplateModelArrayModel.get(int index) Uses Beans introspection to locate a property or method with name matching the key name.CollectionModel.get(int index) Retrieves the i-th object from the collection, wrapped as a TemplateModel.OverloadedMethodsModel.get(int index) SimpleMethodModel.get(int index) BeanModel.getAPI()SimpleMapModel.getAPI()protected TemplateModelBeansWrapper.getInstance(Object object, ModelFactory factory) Deprecated.HashAdapter.getTemplateModel()protected TemplateModelBeanModel.invokeGenericGet(Map classInfo, Class<?> clazz, String key) protected TemplateModelMapModel.invokeGenericGet(Map keyMap, Class clazz, String key) Overridden to invoke the generic get method by casting to Map instead of through reflection - should yield better performance.protected TemplateModelResourceBundleModel.invokeGenericGet(Map keyMap, Class clazz, String key) Overridden to invoke the getObject method of the resource bundle.protected TemplateModelBeansWrapper.invokeMethod(Object object, Method method, Object[] args) Invokes the specified method, wrapping the return value.EnumerationModel.next()Calls underlyingEnumeration.nextElement()and wraps the result.IteratorModel.next()Calls underlyingIterator.next()and wraps the result.protected TemplateModelReads the specified field, returns its value asTemplateModel.protected TemplateModelWraps the object with a template model that is most specific for the object's class.Methods in freemarker.ext.beans with parameters of type TemplateModelModifier and TypeMethodDescriptionvoidBeansWrapper.setNullModel(TemplateModel nullModel) Deprecated.Changing thenullmodel can cause a lot of confusion; don't do it.BeansWrapper.tryUnwrapTo(TemplateModel model, Class<?> targetClass) protected ObjectBeanModel.unwrap(TemplateModel model) BeansWrapper.unwrap(TemplateModel model) Attempts to unwrap a model into underlying object.BeansWrapper.unwrap(TemplateModel model, Class<?> targetClass) Attempts to unwrap a model into an object of the desired class. -
Uses of TemplateModel in freemarker.ext.dom
Classes in freemarker.ext.dom that implement TemplateModelModifier and TypeClassDescriptionclassA base class for wrapping a single W3C DOM Node as a FreeMarker template model.Methods in freemarker.ext.dom that return TemplateModelModifier and TypeMethodDescriptionXPathSupport.executeQuery(Object context, String xpathQuery) final TemplateModelNodeModel.get(int i) -
Uses of TemplateModel in freemarker.ext.jdom
Classes in freemarker.ext.jdom that implement TemplateModelMethods in freemarker.ext.jdom that return TemplateModelModifier and TypeMethodDescriptionNodeListModel.get(int i) Deprecated.Retrieves the i-th element of the node list.Deprecated.Provides node list traversal as well as special functions: filtering by name, filtering by node type, shallow-copying, and duplicate removal. -
Uses of TemplateModel in freemarker.ext.jsp
Classes in freemarker.ext.jsp that implement TemplateModelModifier and TypeClassDescriptionclassA hash model associated with a servlet context that can load JSP tag libraries associated with that servlet context.Methods in freemarker.ext.jsp that return TemplateModelModifier and TypeMethodDescriptionRetrieves a JSP tag library identified by an URI. -
Uses of TemplateModel in freemarker.ext.servlet
Classes in freemarker.ext.servlet that implement TemplateModelModifier and TypeClassDescriptionclassAn extension of SimpleHash that looks up keys in the hash, then in the request, session, and servlet context scopes.final classTemplateHashModel wrapper for a HttpServletRequest attributes.classTemplateHashModel wrapper for a HttpServletRequest parameters.final classTemplateHashModel wrapper for a HttpSession attributes.classA model that when invoked with a 'path' parameter will perform a servlet include.final classTemplateHashModel wrapper for a ServletContext attributes.Methods in freemarker.ext.servlet that return TemplateModelModifier and TypeMethodDescriptionprotected TemplateModelFreemarkerServlet.createModel(ObjectWrapper objectWrapper, javax.servlet.ServletContext servletContext, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Methods in freemarker.ext.servlet with parameters of type TemplateModelModifier and TypeMethodDescriptionvoidIncludePage.execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) protected voidFreemarkerServlet.postTemplateProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Template template, TemplateModel data) Called after the execution returns fromTemplate.process(Object, java.io.Writer).protected booleanFreemarkerServlet.preTemplateProcess(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Template template, TemplateModel model) Called before the execution is passed toTemplate.process(Object, java.io.Writer).voidAllHttpScopesHashModel.putUnlistedModel(String key, TemplateModel model) Stores a model in the hash so that it doesn't show up in keys() and values() methods. -
Uses of TemplateModel in freemarker.ext.util
Subinterfaces of TemplateModel in freemarker.ext.utilModifier and TypeInterfaceDescriptioninterfaceA generic interface for template models that wrap some underlying object, and wish to provide access to that wrapped object.Methods in freemarker.ext.util that return TemplateModelModifier and TypeMethodDescriptionprotected abstract TemplateModelModelFactory.create(Object object, ObjectWrapper wrapper) Create a wrapping model for the specified object that belongs to the specified wrapper.ModelCache.getInstance(Object object) -
Uses of TemplateModel in freemarker.ext.xml
Classes in freemarker.ext.xml that implement TemplateModelMethods in freemarker.ext.xml that return TemplateModelModifier and TypeMethodDescriptionNodeListModel.get(int index) Deprecated.Selects a single node from this model's nodelist by its list index and returns a new NodeListModel containing that single node.Deprecated.Returns a new NodeListModel containing the nodes that result from applying an operator to this model's nodes. -
Uses of TemplateModel in freemarker.template
Subinterfaces of TemplateModel in freemarker.templateModifier and TypeInterfaceDescriptioninterfaceATemplateModelthat can be unwrapped and then it considers a provided desired (hint) class.interface"boolean" template language data type; same as in Java; eithertrueorfalse.interface"collection" template language data type: a collection of values that can be enumerated, but can't be or not meant to be accessed by index or key, nor the number of elements in it is known.interface"collection" template language data type: Adds size/emptiness querybility toTemplateCollectionModel.interface"date", "time" and "date-time" template language data types: corresponds toDate.interface"directive" template language data type: used as user-defined directives (much like macros) in templates.interface"hash" template language data type: an object that contains other objects accessible through string keys (sub-variable names).interface"extended hash" template language data type; extendsTemplateHashModelby allowing iterating through its keys and values.interfaceAdds key-value pair listing capability toTemplateHashModelEx.interfaceDeprecated.UseTemplateMethodModelExinstead.interface"extended method" template language data type: Objects that act like functions.interfaceATemplateModelon which the?apioperation can be applied.interface"node" template language data type: an object that is a node in a tree.interfaceATemplateNodeModelthat supports navigating to the previous and next sibling nodes.interface"number" template language data type; an object that stores a number.interface"string" template language data-type; like in Java, an unmodifiable UNICODE character sequence.interface"sequence" template language data type; an object that contains other objects accessible through an integer 0-based index.interface"transform" template language data type: user-defined directives (much like macros) specialized on filtering output; you should rather use the newerTemplateDirectiveModelinstead.Classes in freemarker.template that implement TemplateModelModifier and TypeClassDescriptionclassAdapts anarrayof a non-primitive elements to the correspondingTemplateModelinterface(s), most importantly toTemplateHashModelEx.classAdapts anEnumerationto the correspondingTemplateModelinterface(s), most importantly toTemplateCollectionModel.classAdapts anIterableto the correspondingTemplateModelinterface(s), most importantly toTemplateCollectionModel.classAdapts anIteratorto the correspondingTemplateModelinterface(s), most importantly toTemplateCollectionModel.classAdapts aListto the correspondingTemplateModelinterface(s), most importantly toTemplateSequenceModel.classAdapts aMapto the correspondingTemplateModelinterface(s), most importantly toTemplateHashModelEx.classAdapts a non-ListJavaCollectionto the correspondingTemplateModelinterface(s), most importantly toTemplateCollectionModelEx.classAn abstract base class for scalars that vary by locale.classA concrete implementation ofLocalizedStringthat gets a localized string from aResourceBundleclassA simple implementation ofTemplateCollectionModel.classA simple implementation of the TemplateDateModel interface.classA simple implementation of theTemplateHashModelExinterface, using its own underlyingMaporSortedMapfor storing the hash entries.classDeprecated.UseSimpleSequenceinstead.final classA simple implementation of the TemplateNumberModel interface.final classA simple implementation of the TemplateScalarModel interface, using a String.classA simple implementation of theTemplateSequenceModelinterface, using its own underlyingListfor storing the list items.classA sequence that wraps aListofTemplateModel-s.Fields in freemarker.template declared as TemplateModelModifier and TypeFieldDescriptionstatic final TemplateModelTemplateScalarModel.EMPTY_STRINGA constant value to use as the empty string.static final TemplateModelTemplateModel.NOTHINGA general-purpose object to represent nothing.Methods in freemarker.template that return TemplateModelModifier and TypeMethodDescriptionDefaultListAdapter.get(int index) SimpleSequence.get(int index) Returns the item at the specified index of the list.Gets a TemplateModel from the hash.TemplateModelListSequence.get(int index) TemplateSequenceModel.get(int index) Retrieves the i-th template model in this sequence.DefaultEnumerationAdapter.getAPI()DefaultIterableAdapter.getAPI()DefaultIteratorAdapter.getAPI()DefaultListAdapter.getAPI()DefaultMapAdapter.getAPI()DefaultNonListCollectionAdapter.getAPI()TemplateModelWithAPISupport.getAPI()Returns the model that exposes the (Java) API of the value.TemplateHashModelEx2.KeyValuePair.getKey()Configuration.getSharedVariable(String name) Gets a shared variable.TemplateModelAdapter.getTemplateModel()TemplateHashModelEx2.KeyValuePair.getValue()protected TemplateModelDefaultObjectWrapper.handleUnknownType(Object obj) Called for an object that isn't considered to be of a "basic" Java type, like for an application specific type, or for a W3C DOM node.protected TemplateModelSimpleObjectWrapper.handleUnknownType(Object obj) Called if a type other than the simple ones we know about is passed in.TemplateModelIterator.next()Returns the next model.Wraps the parameter object toTemplateModelinterface(s).Makes aTemplateModelout of a non-TemplateModelobject, usually by "wrapping" it into aTemplateModelimplementation that delegates to the original object.protected final TemplateModelWraps the passed object into a template model using this object's object wrapper.DefaultObjectWrapper.wrapDomNode(Object obj) Methods in freemarker.template with parameters of type TemplateModelModifier and TypeMethodDescriptionbooleanDefaultNonListCollectionAdapter.contains(TemplateModel item) voidTemplateDirectiveModel.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.voidConfiguration.setSharedVariable(String name, TemplateModel tm) Adds a shared variable to the configuration.ObjectWrapperAndUnwrapper.tryUnwrapTo(TemplateModel tm, Class<?> targetClass) Attempts to unwrap aTemplateModelto a plain Java object that's the instance of the given class (or isnull).ObjectWrapperAndUnwrapper.unwrap(TemplateModel tm) Unwraps aTemplateModelto a plain Java object. -
Uses of TemplateModel in freemarker.template.utility
Classes in freemarker.template.utility that implement TemplateModelModifier and TypeClassDescriptionclassDeprecated.Use block-assignments instead, like<assign x>...</assign>.classDeprecated.UseNodeModelinsteadclassGives FreeMarker the the ability to execute external commands.classPerforms an HTML escape of a given template fragment.classTransformer that supports FreeMarker legacy behavior: all newlines appearing within the transformed area will be transformed into the platform's default newline.classAn object that you can make available in a template to instantiate arbitrary beans-wrapped objects in a template.classA filter that compresses each sequence of consecutive whitespace to a single line break (if the sequence contains a line break) or a single space.classPerforms an XML escaping of a given template fragment.Methods in freemarker.template.utility that return TemplateModelMethods in freemarker.template.utility with parameters of type TemplateModelModifier and TypeMethodDescriptionstatic StringClassUtil.getFTLTypeDescription(TemplateModel tm) Returns the type description of a value with FTL terms (not plain class name), as it should be used in type-related error messages and for debugging purposes.static ObjectDeepUnwrap.permissiveUnwrap(TemplateModel model) Same asDeepUnwrap.unwrap(TemplateModel), but it doesn't throw exception if it doesn't know how to unwrap the model, but rather returns it as-is.static ObjectDeepUnwrap.premissiveUnwrap(TemplateModel model) Deprecated.the name of this method is mistyped.static ObjectDeepUnwrap.unwrap(TemplateModel model) UnwrapsTemplateModel-s recursively.
BeansWrapper.getModelFactory(Class)instead.