How can I pass a variable (e.g: String myvar= "Hello World";) from my java class to my template file called test.vm ?
I was following the Admin UI tutorial, but that part is not very clear, or not covered.
At this moment I have the following code :
String myvar = "Hello World"; context.put("myvar",myvar); response.setContentType("text/html;charset=utf-8"); templateRenderer.render("test.vm", response.getWriter());
Please also provide the code which belongs in the *.vm file. I'm assuming you use $myvar ?
Here is some sample code showing how to pass variables into a velocity template in an HttpServlet (in this case our variables control whether or not to show an OAuth button on a settings page):
Integer OAuthed = 0;
Map<String, Object> context = new HashMap<String, Object>();
renderer.render("admin.vm", context, response.getWriter());
We use the variables in the velocity template file (ours was called admin.vm) like this:
#if ($OAuthed == 1)
<a href="/jira/plugins/servlet/test/admin?clearOAuth=1">Clear OAuth</a>
You also need to use these dependencies in your HttpServlet:
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