3 Rendering - Reference Documentation
Authors: Grails Plugin Collective
Version: 1.0.0
3 Rendering
There are four services available for rendering:- pdfRenderingService
- gifRenderingService
- pngRenderingService
- jpegRenderingService
OutputStream render(Map args, OutputStream destination = new ByteArrayOutputStream())
args
define the render operation, with the bytes written to the given output stream. The given output stream is returned from the method. If no destination
is provided, the render will write to a ByteArrayOutputStream
that is returned.Here are some examples:// Get the bytes def bytes = gifRenderingService.render(template: '/images/coupon', model: [serial: 12345])// Render to a file new File("coupon.jpg").withOutputStream { outputStream -> jpegRenderingService.render([template: '/images/coupon', model: [serial: 12345]], outputStream) }
Basic Render Arguments
All rendering methods take aMap
argument that specifies which template to render and the model to use (in most cases).The following map arguments are common to all rendering methods:
template
(required) - The template to rendermodel
(optional) - The model to useplugin
(optional) - The plug-in containing the templatecontroller
(optional) - The controller instance or name to resolve the template against (set automatically in providedrender«format»
methods on controllers).
Template Resolution
The plugin uses the same resolution strategy as therender()
method in Grails controllers and taglibs.That is,
- template files must start with an underscore (
_template.gsp
) - template paths starting with "/" are resolved relative to the
views
directory - template paths NOT starting with "/" are resolved relative to the
views/«controller»
directory
template
argument does not start with a "/", the controller
argument must be provided. The methods added to controllers (e.g. renderPdf()
) automatically pass the controller
param for you.