Containers
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 sub variables of the hash.
The commonly used implementation is SimpleHash
, which implements TemplateHashModelEx
. Internally it uses a java.util.Hash
to store the sub variables. 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 sub variables 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 sub variables. SimpleSequence
has methods by which you can add sub variables. 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 TemplateModelException
s.
The commonly used implementation is SimpleCollection
.