The SPA renderer uses different
techniques to render a page.
The rendering process is executed by
info.magnolia.rendering.engine.RenderingFilter. The
result of the renderer is written to
ServletOutputStream
and sent to the browser. For further details, see
Rendering content.
Magnolia provides the following renderers out of the box:
Fully qualified class name. Must implement the info.magnolia.rendering.renderer.Renderer
interface.
contextAttributes
A map to register components that are injected into the rendering
context. The components can be used within the template scripts with
their given names.
componentClass
The fully qualified class name of the context attribute component.
name
The name of the component to add to the context. Use this name to
reference the component in a template script.
Renderers provided by Magnolia
Magnolia provides a number of renderers out-of-the-box.
Use the default Magnolia renderers as a base. Extend them to define your
own new renderers using YAML inherit or similar techniques to
reuse the configuration.
Note that magnolia-rendering is available in every
preconfigured Magnolia bundle or
webapp, whereas magnolia-site is available in every preconfigured
Magnolia bundle or webapp exceptmagnolia-empty-webapp.
FreeMarker renderer
The FreeMarker renderer is used to render pages relying on templates
with FreeMarker-based template scripts.
The FreeMarker renderer can be considered as the standard Magnolia
renderer. It is also the base for the #_site_aware_renderers.
The implementation class is
info.magnolia.rendering.renderer.FreemarkerRenderer.
Some parts of the configuration are added by modules which provide
components registered in contextAttributes.
FreeMarker exception handling
FreeMarker exceptions render differently on the author and public
instances. On author, FreeMarker exceptions show the stack trace in a
yellow block with red text, and on public errors are hidden and logged.
This behavior is controlled by
info.magnolia.freemarker.ModeDependentTemplateExceptionHandler
registered in /server/rendering/freemarker/templateExceptionHandler.
You can extend this class to fine-tune behavior.
FreeMarker security
Magnolia extends FreeMarker’s DefaultMemberAccessPolicy with a configurable list of blacklisted classes.
If you want to add more classes to the default configuration, import this YAML bootstrap file into configuration:/server/rendering/freemarker/ and add your entries.
A site-aware renderer resolves the site
definition related to the given request and merges the template
definition of the requested page with the
template prototype
from the site definition.
The magnolia-site module
adds the
sitefn
context attribute to the freemarker renderer configuration and
configures the site renderer in /modules/site/renderers.
Site-aware renderers are implemented by the
info.magnolia.module.site.renderer.SiteAwareRendererWrapper class.
It is a wrapper that relies on another already existing renderer. It
comes with the property wrappedRendererType, which must be configured.
The value of this property is the name of the wrapped renderer.
The SPA (Single-Page
Application) renderer produces template annotations, which the Pages
app transforms into the green toolbars – editable page elements.
The implementation class is info.magnolia.rendering.spa.renderer.SpaRenderer.
Rendering single-page applications (SPA)
Currently, the following functionalities are not supported in SPA rendering:
Streams the binary data stored in the content or loads it from an
arbitrary path.
Creating a custom renderer
To create your own renderer, extend
info.magnolia.rendering.renderer.AbstractRenderer. This
convenience class supports typical functionality such as setting context
attributes and executing a rendering model. It sets up the context by
providing the following objects: