|
Data Models that Implement more than one InterfaceMore than one template model can be implemented at a time for a given class. For instance, a class could have the following signature: public class MyModel implements TemplateHashModel, TemplateMethodModel, TemplateSequenceModel { // Implementation goes here... } When presented with a class such as the above, FreeMarker will attempt
to "do the right thing". Supposing such a class was placed inside
a <comment> The following will index element one of the TemplateListModel implementation... </comment> The second element of the list is: ${demo[ 1 ]} <comment> The following will reference the key name "hello" of the TemplateHashModel implementation... </comment> Say hello: ${demo.hello} And again: ${demo[ "hello" ]} <comment> The following will call the "demo" method (the TemplateMethodModel implementation)... </comment> Call from the demo() method... ${demo()} CaveatsIn the case of dynamic key syntax, if your model implements
both If you use dot notation (eg. There is sometimes actually something of an ambiguity in the
template language when an object implements more than one of the
core interfaces. For example, if a model implements both TemplateScalarModel
and TemplateSequenceModel, there is ambiguity as to whether
("" + myModel)[1..3] The expression |
|