Similar content

Loading

Powered by Canoo FindIT.

Templating

Configured renderable definitions

Page, component and area definitions represent the static configuration for these objects. They are instantiated with the content2bean mechanism, so you can define and use your own subclasses if needed. This can be useful, for example, if your pages, areas or components need specific configuration that you don't want to expose to editors in dialogs: the same script and the same dialog can be re-used to render totally different looking components, for example. The definition instances must be stateless as they are reused across the system.

Model

Renderable elements (pages, areas, components) can also take advantage of a model. This is a similar to the "action" in an action-based Web framework. Model classes are instantiated per rendering. As such, they can be used to perform actions based on input, load some data, or simply provide utility methods to the templates.

The following class diagram shows the relationships between the objects collaborating in the rendering of a template.

The sequence diagram below shows the template rendering process starting from when the request passes through the AggregatorFilter in Magnolia's filter chain.

Templating support objects

There are a couple of objects that are made available to template scripts, to simplify their development:

content Current node exposed as a map like cms:setNode.
page or actpage Current page exposed as a map like cms:setNode. This attribute is called actpage in JSP because the name page is reserved.
def Current RenderableDefinition. (template or paragraph definition object)
model The bean created by the renderer based on the modelClass defined on the paragraph or template definition. The current content, definition and the parent model are passed to the constructor.
actionResult The result of the model's execute method. This string can be used to determine the template (in the definition) or in the template itself.
mgnl An object providing access to various components or utility methods, for example to create links. See MagnoliaTemplatingUtilities.
ctx Current Context. Depending on the type of request, a different implementation will be used but for a web request to a page this will be a WebContext instance. In a web request, you can use ${ctx.contextPath} to get the context path corresponding to the current request.
state Current AggregationState.
stk Provides access to STK templates. The stk object is an exposed STKUtil class, similar to how mgnl is an exposed MagnoliaTemplatingUtilities class.
i18n Messages from the current message bundle like the "Read on" message. i18n["key"]