Rendering a template¶
To render any template, an instance of gg.jte.TemplateEngine
is required. Typically, you create it once per application (it is safe to share the engine between threads):
With the TemplateEngine ready, templates are rendered like this:
Where output
specifies where the template is rendered and model
is the data passed to this template, which can be an instance of any class. Ideally, root templates have exactly one data parameter passed to them. If multiple parameters are required, there is a render
method overload that takes a Map<String, Object>
.
TemplateOutput
implementations
Besides gg.jet.output.StringOutput
, you can use several other gg.jte.TemplateOutput
implementations or create your own if required.
gg.jte.output.StringOutput
- writes to aString
gg.jte.output.FileOutput
- writes to the givenjava.io.File
gg.jte.output.PrintWriterOutput
- writes to aPrintWriter
, for instance, the writer provided byHttpServletRequest
gg.jte.output.WriterOutput
- writes to ajava.io.Writer