So far this book has discussed only single-template applications, but your Zen Mojo application can use multiple template classes, which enables you to divide your application code into more easily maintained units.
Zen Mojo provides two ways to work with multiple templates: explicit dispatch (discussed in the previous chapter
) and dynamic dispatch (discussed in this chapter). In either case, the methods in the templates can use all the tools described in the earlier chapters of this book.
This chapter discusses the following topics:
Compared to explicit dispatch, the dynamic dispatch mechanism uses a larger set of small templates. Each template is key-specific and provides only one part of the page logic. For example, one template might only return content objects for a specific key. Another template would only handle select events for the same key.
When the dynamic dispatch mechanism is enabled (via the templateDispatchMode
property), Zen Mojo checks for a key-specific template at several specific points within the page logic, loads the template, and then uses it for the designated purpose. Specifically, if dynamic dispatch is enabled:
In dynamic dispatch, Zen Mojo finds the template to load as follows:
Zen Mojo looks for a template in the following XML namespace:
In this namespace, Zen Mojo loads the template whose short class name is key
, where key
is the current key.
Note that this discussion assumes that you are using data
as the provider name when you are retrieving data objects and that you are using layout
as the provider name when you are retrieving layout graphs.
To modify the page class to use dynamic dispatch:
Property templateDispatchMode As %ZEN.Datatype.boolean [ InitialExpression=1] ;
For example, the Zen Mojo plugin reference documentation application uses this value:
Property templateDispatchBaseNamespace As %ZEN.Datatype.string
[ InitialExpression="http://www.intersystems.com/zen/mojo/documentation"] ;
To enable dynamic dispatch, define a set of templates in three groups.
For clarify and ease of maintenance, you could place these groups of template classes in subpackages named Data
, and Events
, respectively. For an example, see the %ZEN.Mojo.PluginDocumentation.Templates
package, which is part of the plugin reference documentation application.