Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to Concatenate two variable in Velocity Code

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?


1 answer

0 votes
Bill Bailey Community Leader Dec 23, 2020

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 Still no avail.

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:

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:






Ok. will have to reach out to, 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

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()

Bill Bailey Community Leader Dec 25, 2020

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?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Confluence

Announcing Team Calendars in Confluence Data Center

Hi Community! We're thrilled to share that Team Calendars for Confluence is now a built-in feature for Confluence Data Center releases 7.11 and beyond.  A long time favorite,  Team Cale...

198 views 0 6
Read article

Community Events

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

Events near you