jte-models Facade Generator¶
jte-models is a generator extension for jte which creates a typesafe facade for rendering templates.
To use jte-models, set up your build script to include one of these:
Run the build to generate classes.
Additional generated classes will include a facade interface named
gg.jte.generated.precompiled.Templates, with implementations:
Templates has a method for each of your templates, for example:
The package name can be changed by setting the packageName option in the build.
First, construct an instance of
Templates. If you are using a dependency injection framework, you could make a factory for this. Otherwise, use
new StaticTemplates() or
To use, call a template method to get a
JteModel object, then call one of its
render methods. For example:
Static vs. Dynamic¶
StaticTemplates is built so that it calls directly to jte generated render classes, with no reflection used. This is good for a production build.
DynamicTemplates delegates to a
TemplateEngine, so it can be set up to hot-reload templates. This is good for development. You will still have to rerun the build if @params of a template are changed.