Redemption of Atlassian Answers T-Shirts, Backpacks and Jackets is temporarily unavailable while we migrate to a new third-party provider for https://swag.atlassian.com.
How can I init() velocity and make use of a velocity template within JIRA for something other than, for example, a customfield?
Say that I wanted to make a custom message as a comment or something - upon issue created via an event listener, lets say I want something simple like using the example from http://velocity.apache.org/engine/devel/developer-guide.html#thevelocityhelperclass but having the variables "name" and "project" set via selections in custom fields?
EDIT: if I used the example from apache I get this error..
There seem to be at least two questions in there, here is an answer regarding Velocity initialisation:
There are a bunch of ways that you can initialize Velocity. Depending on your context (heh). Simply you could do this:
You can add whatever inputs you need, and use velocity markup to manipulate those values and render.
The injected helpers are for when you have an Xwork action /other, and want those helpers to be available in the velocity context for rendered templates. Im not exactly clear on what you're trying to do.
Hi, and thanks for your reply! I was wondering about this:
is DIRNAME_PATH and FILENAME supposed to be:
I tried that but my renderedText is set to null, what am I doing wrong? If you could give me a pointer or two (:
I looked for more on Jira/Atlassian VelocityManager, but didnt find more on the methods:
DIRNAME_PATH refers to an actual template .vm file thats packaged with your plugin, it would be relative, eg under src/main/resources (source path), you would have 'templates/yourplugin/thing.vm', so DIRNAME_PATH = "templates/yourplugin/"; // note the trailing / ... the number of times...
FILENAME is then just "thing.vm". k?
Regarding impl, you dont say what JIRA rev you are using. Im at 5.0.x? Also, don't use the impls, use the interfaces, use dependency injection or the ComponentManager/ComponentAccessor to retrieve implementations.
getEncodedBodyForContent is interesting as it doesnt use resources packed with your plugin, it can use derived/retrieved data to the the rendering. This is good and bad, in that templates wouldn't therefore get cached, and will put more io load on the app to retrieve said template....
Yeah, thats what I thought before I posted the reply above, but I get an error that the template couldnt be found although it is present at "<my plugin>/src/main/resources/mytemplate.vm":
What I did was:
Or does the template have to reside within the actual Jira install-dir and not within the plugin?
A follow-up question, can the .vm be added to the atlassian-plugin.xml as some other kind of resource (other than view/edit/create/search, for like customfields and such..)? I read a post on the old jira forums for something in that fashion but I cannot seem to find it now ):
I think there is some confusion regarding compile time and deployment time paths. src/main/resources is only applicable at DEV time. Once compiled, you will find all resources and paths under /src/main/resources become 'top level' as far as your output JAR is concerned, for example, a folder located in your /src/main/resources/templates directory will become /templates after compilation and inclusion in a jar.
Regarding your second question (2 for the price of one?!) you _only_ need to specify a .vm resource in the plugin.xml file if it is required, such as for an XWork action. If you are doing a 'roll your own' velocity render, then you do not need to specify it anywhere.
Thanks a lot for helping out Andy (: !