Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to render Velocity Template?

I'm writing a JIRA plugin and I need to render a velocity template that I have written. My code is in src/main/package/ and my template is in /src/main/resources/templates/packageName/template.vm. How should I render the template from so I can get the String contents of it?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

Hello Bob.

It depends on what kind of plugin you develop.

If you develop the servlet it looks like:

public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException, ServletException {
final Map<String, Object> context = new HashMap<String, Object>();
context.put("yourVarName", "Your Value");
templateRenderer.render("templates/packageName/template.vm", context, response.getWriter());

But if its Web Action for example so you need to configure the atlassian-plugin.xml

Like the following:

<webwork1 key="actions" name="Name" class="java.lang.Object">
            <action name="package.MyClass" alias="MyClass">
                <view name="success">templates/packageName/template.vm</view>

In your first example you use templateRenderer without ever declaring it. How do I get an instance of it? Also, can you give me a link that describes what a web action is? Thanks

TemplateRenderer you must initiate via the constructor like this: import com.atlassian.templaterenderer.TemplateRenderer; public class YourClass { private final TemplateRenderer templateRenderer; public YourClass(TemplateRenderer templateRenderer) { this.templateRenderer = templateRenderer; } } Also you need to import it in the atlassian-plugin.xml <component-import key="renderer" interface=""/> Here is the link for WebAction documentation.

Eclipse is telling me that, "The import com.atlassian.templaterenderer cannot be resolved". I have added the line to my atlassian-plugin.xml as well.

Add a dependency <dependency> <groupId>com.atlassian.templaterenderer</groupId> <artifactId>atlassian-template-renderer-api</artifactId> <version>1.3.1</version> <scope>provided</scope> </dependency> Into your pom.xml

I added that to pom.xml and I still get the same error in Eclipse. When I build the project using the atlas-mvn command, the error I get is: "cannot find symbol class TemplateRenderer"

Could you show your java class, atlassian-plugin.xml and pom.xml dependencies?

Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

33 views 1 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you