Data Models

Models Introduction

Each node in the data model tree must implement one of the subinterfaces of TemplateModel. The root node must implement TemplateModelRoot. The other nodes must implement one of the following:

If that sounds like a lot to understand, don't worry, the following sections will explain them all.

All of the TemplateModels can throw TemplateModelExceptions. Normally when a TemplateModelException is thrown, FM-Classic will embed the error message in the output, inside an HTML comment. This behaviour is controlled by the Event Listeners, as discussed in later sections.

The TemplateModel interface itself declares one method: the isEmpty() method. If the TemplateModel is empty, for instance when a list contains no values, a hash is empty, or a scalar has no value, this method should return false. This method also controls the behaviour of the Method Models and the Transform Models, as described in later sections.

Finally, the isEmpty() method is used by FM-Classic to check for boolean values. If the method returns true, the boolean value of false is used within boolean expressions, and vice-versa.