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
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
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.
${ctx.aggregationState.channel.name}
${ctx.getAggregationState().getChannel().getName()}
content
Current content node in the rendering context provided as a
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
ContentMap
.
- In a page template, current node is the page node (
mgnl:page
). - In a component template, current node is the component node. It is the contextual "root" content node.
The current node is exposed as a ContentMap object, which means it of the Node.
Example: Rendering a page title. Here the current node is a page node.
<h1>${content.title!""}</h1>
def
Current
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
RenderableDefinition
. Use
def
to access the properties of the template definition such as title or
custom parameters.
- Page, area or component template definition object.
- 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.
[#assign cssClass=def.parameters.cssClass]
model
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
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
RenderingModel
interface which provides bean properties for: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 def
above.
Other properties depend on the implementation of the model, but they should be bean properties too.
Example: Asking a model for a URL and a title, then building a link.
[#assign linkURL = model.url!]
[#assign linkText = model.title!]
<a href="${linkURL}">${linkText}</a>
action
A String returned by the execute()
method of the model class. 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.
ctx
Context represents the environment in which the current process runs. The type is $webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Context
. It is a
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
WebContext
when the script is executed from a Web page and
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
SimpleContext
for instance when the script generates a mail from within a workflow or scheduled job.
The
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Context
interface provides access to:
user
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
User
)locale
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Locale
)
In addition,
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
WebContext
provides access to:
aggregationState
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
AggregationState
)contextPath
(current context path)request
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
HttpServletRequest
)servletContext
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
ServletContext
)
WebContext properties are null if the execution is not a Web page request.
Example: Getting a search query from a request parameter.
[#assign queryStr = ctx.getParameter('queryStr')!?html]
state
The current
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
AggregationState
. Only set if ctx is of type WebContext. (See above.) It is a shortcut for
ctx.aggregationState
. Provides access to many properties as:
channel
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Channel
)originalURI
currentURI
queryString
mainContentNode
($webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Node
)templateName
locale
(the same as ctx.locale
)- etc.
Read the javadoc (
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
AggregationState
) for all the properties.
i18n
A message bundle wrapper (
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
MessagesWrapper
) to retrieve translated keys of a
message bundle according to the current
$webResourceManager.requireResource("info.magnolia.sys.confluence.artifact-info-plugin:javadoc-resource-macro-resources")
Locale
.
The basename of the message bundle must be defined in the Template definition.
Use it to internationalize labels which are not stored in content. (See template labels).
Example:
#trackbackRdf ($trackbackUtils.getContentIdentifier($page) $page.title $trackbackUtils.getPingUrl($page))