Last updated Oct 30, 2024

Atlassian Template Renderer

Use the Atlassian Template Renderer (ATR) to render your textual content. ATR is a library that provides an abstraction on top of various template engines, making it easier to use the template engines. For example, instead of having to create a VelocityEngine object and configure it, we provide a factory to do that for you. See the Javadoc for reference information.

The following sections describe how to use the ATR.

The simple case

In your atlassian-plugin.xml file, specify the component-import module as follows:

1
2
<component-import key="velocity-renderer" interface="com.atlassian.templaterenderer.TemplateRenderer" />

Now just setup the TemplateRenderer component for injection into your component.

When you need to render a template, call the renderer.render(String templateName, Writer writer) or renderer.render(String templateName, Map<String, Object> context, Writer writer) method.

A bit more sugar

Let's say you want one of the other components injected into each of the template contexts for you to use. You could make sure to have that component injected anywhere you do some rendering and then creating a context map with the component in it. But there's an easier way. Specify the component as a template-context-item.

1
2
<template-context-item key="rendererHelperContextItem" component-ref="rendererHelper"
    context-key="helper" name="Renderer Helper Context Item"/>

Using this technique, the ATR plugin makes the SAL I18nResolver and the plugins WebResourceManager automatically available to all templates in this way with the i18n and webResourceManager context keys.

Rate this page: