Another thing that lists can do is provide a way of indexing into
a given point in the list. To support this, the TemplateIndexModel
interface can be used:
public TemplateModel getAtIndex(long index) throws TemplateModelException;
The above method is used by FM-Classic when a template wants to index
directly into a list. We pass in a long
rather than an
int
to match the precision FM-Classic uses for its number
models. If in practise, you templates only use the foreach
or list
syntax, this interface is not required.
An index model can become a writeable model by implementing the
TemplateWriteableIndexedModel
interface. This extends
the TemplateIndexedModel
and adds the following method:
public void putAtIndex(long index, TemplateModel model) throws TemplateModelException;
The supplied TemplateModel will replace any existing TemplateModel at the given index.
Previous: List Model | Next: Hash Model |