I am creating a User Macro in Confluence using Velocity Code. Need to concatenate two variables
using below code
##set($listofContent = $labelManager.getCurrentContentForLabelAndSpace() )
## set($labelManager = $action.getLabelManager() )
##set($label = $labelManager.getLabel() )
##set($newLabel = "")
##set($oldLabel = "")
#foreach ($labelling in $page.getLabellings () )
#set ($label = $labelling.getLabel() )
#set ($oldLabel = $label)
##here I would like to concatenate Old Label + New Label, so that I can get all labels
##below command is not working
#set ($newLabel = $oldLabel$newLabel)
## where am I going wrong?
#end
Well straight concatenation would just be
#set ($newLabel = $oldLabel + $newLabel)
But if $oldLabel = "foo" and $newLabel = "bar", then the result will be foobar. So if you want some sort of delimiter, then you need to do something like this:
#set ($newLabel = $oldLabel + ', ' + $newLabel)
to result in foo, bar
@Bill Bailey : While old label prints the latest label on a page, newlabel would simply print $newLabel as the value of label, with both the options provided.
I tried setting the initial values as
##set($newLabel = ' ')
##set($oldLabel = ' ' )
That did not help either. Referred and implemented from this link http://people.apache.org/~henning/velocity/html/ch09s05.html. Still no avail.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You do realize that ## is the syntax for a comment, so those lines will not operate?
I would also suggest looking at the latest guide:
http://velocity.apache.org/engine/2.2/user-guide.html#string-concatenation
It suggest using
#set ($newLabel = $oldLabel$newLabel)
But I have typically used the + operation as I often need to mix in HTML code. Either should work.
It has been awhile since I worked with labels, but you may have to convert the object to a string one of two ways:
$label.toString()
or
$label.name
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok. will have to reach out to dev@velocity.apache.org, as trying all options has not worked. FYI, without converting oldLabel is printing the latest label as it is. Hence..
But, Thanks for offering the advice
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, I don't think I have seen a method .getLabellings () (note that there should not be space between the method and () ).
The method I have always used was .getLabels()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Bailey Space was a typo. I referred example given at https://community.atlassian.com/t5/Confluence-questions/How-do-I-list-all-pages-with-titles-and-last-modified-by-and/qaq-p/41974. getLabel is working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yeah, that article is from 2015 so I think version 5. It may be that .getlabellings() was deprecated, or a method added by another plugin?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.