Our company has begun using Confluence wiki as a documentation site for our teams, and we are implementing a macro called PocketQuery.
This macro pulls SQL data into the site dynamically (we are pulling information like site contacts).
It uses Velocity Templates to display it's data, however I am having issues when doing simple array indexing.
The code:
#set ( $page = $additionalParams.get('Page') )
#set ( $pages = "" )
#if ( $page != $null && $page != "" )
#set ( $pages = $page.split(";") )
#else
#set ( $pages = [] )
#end
The $additionalParams
is a list that has been initialised outside of the template, and contains the parameters being passed into macro, in this case:
Page=Site Name;Server
The code I am trying to setup is pulling the Name;Server
value from the $additionalParams
list, split the value if it is not empty, and then obtain the first value.
I have tried:
$pages.get(1)
$pages[1]
However no value gets pulled (I have also tried zero as an index - same result).
Foreach-ing through this array and printing each entry does work - meaning there are values in there.
All I want to be able to do is index into the array - Can't seem to dig up anyway of doing this.
Could this be converted to a list so it can use the $pages.get
method to index into it?
Extending on that would this allow me to use $pages.contains
method?
Confluence is using Velocity 1.6.
EDIT:
The solutions on this page and on this page do not work - I am guessing (Wildly) maybe the correct objects are not in the context for the template to use them?
(Would PocketQuery or Confluence be doing this?)
How would I go about using the 'ListTool' ?
$page != $null || $page != ""
seems wrong - I think you want to use&&
there. – Lopes$pages.get(0)
to get the first value, since arrays have zero-based indexes. – Lopes