Containers

Page Contents

These are hashes, sequences, and collections.

Hashes

Hashes are java objects that implement TemplateHashModel interface. TemplateHashModel contains two methods: TemplateModel get(String key), which returns the subvariable of the given name, and boolean isEmpty(), which indicates if the hash has zero subvariable or not. The get method returns null if no subvariable with the given name exists.

The TemplateHashModelEx interface extends TemplateHashModel. It adds methods by which values and keys built-ins can enumerate the subvariables of the hash.

The commonly used implementation is SimpleHash, which implements TemplateHashModelEx. Internally it uses a java.util.Hash to store the subvariables. SimpleHash has methods by which you can add and remove subvariable. These methods should be used to initialize the variable directly after its creation.

Containers are immutable within FTL. That is, you can't add, replace or remove the subvariables they contain.

Sequences

Sequences are java objects that implement TemplateSequenceModel. It contains two methods: TemplateModel get(int index) and int size().

The commonly used implementation is SimpleSequence. It uses internally a java.util.List to store its subvariables. SimpleSequence has methods by which you can add subvariables. These methods should be used to populate the sequence directly after its creation.

Collections

Collections are java objects that implement the TemplateCollectionModel interface. That interface has one method: TemplateModelIterator iterator(). The TemplateModelIterator interface is similar to java.util.Iterator, but it returns TemplateModels instead of Object-s, and it can throw TemplateModelExceptions.

The commonly used implementation is SimpleCollection.

FreeMarker Manual -- For FreeMarker 2.3.20
HTML generated: 2013-06-27 20:54:33 GMT
Edited with XMLMind XML Editor
Here!