Rendering context objects provide direct access to important Magnolia classes from a template script. You can get information such as the current template, user and request through these objects. Rendering content objects are set in AbstractRenderer and its child classes.
Most context objects are JavaBeans, which means you can access their properties with the "dot" operator or a getter method in a template script. Both expressions are valid and return the same value.
Current content node in the rendering context provided as a ContentMap.
In a page template, current node is the page node (
mgnl:page). In a component template, current node is the component node (
mgnl:component). It is the contextual "root" content node. The current node is exposed as a ContentMap object, which means it carries the properties of the underlying Node.
Example: Rendering a page title. Here the current node is a page node.
def to access the properties of the template definition such as title, or custom parameters. It is a JavaBean, which means you can access its properties with the "dot" operator or a getter method.Example: Getting a CSS class name from custom parameters and assigning it to a variable.
A JavaBean created by the renderer based on the model class defined in the template definition. Not every template defines a model class. If no model is defined no bean is created and its reference is null.
Every model class must implement the RenderingModel interface which provides bean properties for:
model itself provides the following built-in properties:
parent: Model of the parent component or template.
root: Top root model of the rendering process.
content: Content node bound to the model in the rendering context provided as a ContentMap.
node: Content node bound to the model in the rendering context provided as a Node.
definition: The renderable definition (template, area or component) bound to the model. Same as
These properties can referenced like this:
The probably most handy property is
parent. Parent points to the parent model, its meaning depends on the case. If you have for instance a component template with a model and a page template with a model - the parent model of the component template is the model of the page template. Via parent you can access all built in properties of the parent model like this:
Example: Asking a model for a URL and a title, then building a link.
A String returned by the
execute() method of the model class. Can be used for logic that has to be executed before rendering, when rendered output depends on the result of the logic, for example form field validation before rendering the field.
Context represents the environment in which the current process runs. The type is Context. It is a WebContext when the script is executed from a Web page and SimpleContext for instance when the script generates a mail from within a workflow or scheduled job.
The Context interface provides access to:
In addition, WebContext provides access to:
contextPath(current context path)
WebContext properties are null if the execution is not a Web page request.
Example: Getting a search query from a request parameter.
The current AggregationState. Only set if ctx is of type WebContext. (See above.) It is a shortcut for
Provides access to many properties as:
locale(the same as
Read the javadoc (AggregationState) for all the properties.
Use it to internationalize labels which are not stored in content. (See template labels).