Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Load Velocity template from java on JIRA

Rui Rodrigues
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2015

Hi There,

 

Is possible to load a Velocity template from java code? In may case, I'm creating a jira-footer and I've a 

PluggableFooter class that has a method called 

getFullFooterHtml

I need todo something like this

// Create the Velocity Context

        Map context = MacroUtils.defaultVelocityContext();

        context.put("myCustomVar", customVar);

        context.put("otherCustomVar", otherCustomVar);

        // Render the Template

        String result = VelocityUtils.getRenderedTemplate("/com/myplugin/templates/macro.vm", context);

Any suggestion?

Cheers,

RMRodrigues.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Rui Rodrigues
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2015

I think that I've found a possible solution. I'm doing some testes.

Solution:

Map<String, Object> context = new HashMap<String, Object>();

VelocityManager velocityManager = ComponentAccessor.getVelocityManager();

String webworkEncoding = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_WEBWORK_ENCODING);
String renderedText = velocityManager.getEncodedBody("/templates/", "MyTemplate.vm",

                "Base URL Here...", webworkEncoding, context);

I will confirm if that is the solution.

Thanks.

Rui Rodrigues
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2015

This solution is working fine.

1 vote
Newbie April 29, 2015

Hey,
replace this line:

String result = VelocityUtils.getRenderedTemplate("/com/myplugin/templates/macro.vm", context);


with this line:

String result = VelocityUtils.getRenderedTemplate("templates/macro.vm", context);
return result;
Rui Rodrigues
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2015

The class VelocityUtils is not available on JIRA. It's available on Confluence only I think.

Newbie April 29, 2015

OK, that's not good.

0 votes
GabrielleJ
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2015

We have done this with our instance. Depending on your JIRA version, find the soy template for the footer. Usually it can be found in root/app/static/email/global-footer.soy

Rui Rodrigues
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 29, 2015

Hi Gabrielle, Thank for your response. I've a Velocity template and not a SOY template. I need to load my Velocity template from java class and return its content processed. Thanks.

TAGS
AUG Leaders

Atlassian Community Events