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

Your Points Tracker
Challenges
Leaderboard
  • 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
Recognition
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?
Kudos
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/MyClass.java and my template is in /src/main/resources/templates/packageName/template.vm. How should I render the template from MyClass.java 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");
response.setContentType("text/html;charset=utf-8");
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">
        <actions>
            <action name="package.MyClass" alias="MyClass">
                <view name="success">templates/packageName/template.vm</view>
            </action>

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="com.atlassian.templaterenderer.velocity.one.six.VelocityTemplateRenderer"/> Here is the link for WebAction documentation. https://developer.atlassian.com/jiradev/jira-architecture/building-jira-add-ons/jira-plugins2-overview/jira-plugin-module-types/webwork-plugin-module

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?

TAGS
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