Is it possible to use arrays in velocity in Confluence? According to this post:
https://answers.atlassian.com/questions/317/which-version-of-velocity-is-used-for-confluence
Confluence (I'm on 3.5.x) is using velocity 1.6.1, which according to this:
http://stackoverflow.com/questions/191844/what-is-the-best-way-to-access-an-array-inside-velocity
says I should be able to use $myArray.get($index), but this is giving me an odd stack trace:
java.lang.NullPointerException at com.atlassian.confluence.velocity.introspection.ReturnValueAnnotator.getAnnotationsForMethod(ReturnValueAnnotator.java:18)
I'll file a bug report if necessary but wanted to check here first to see if I was way off base.
Community moderators have prevented the ability to post new answers.
I get the same error in Confluence 4.1.
However, if you convert the array into a list, $myListThatWasAnArray.get($index) works fine.
Do you know how to convert the array into list directly on Velocity file. It would be helpful for all of us when we want to modify the core velocity file and add some logics. :D Thank you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use this trick directly on velocity file to get the ith element, or get the size of the array. In this code example, I take the first element of the array
#set ($counter = 0)
#set ($value = "")
#foreach ($item in $array)
#if($counter == 0)
#set ($value = $item)
#end
#set ($counter = $counter +1)
#end
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm getting the same in Confluence 4.2 trying to write a user macro. Very frustrating. I can only look through the array using #foreach but can't use any of the List methods that are apparently supported in this version of Velocity.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.