Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Velocity Variable(use together string and integer variables)

Tags:

velocity

xwiki

How can I use String and Integer variables it together in "Velocity"?

#set ($var1 = "exp"+1)

I tried a few times but I could not.

Any help will be highly appreciated.

like image 274
ahta14 Avatar asked Oct 25 '25 22:10

ahta14


1 Answers

If you were trying to do concatenation, it's not supported by Velocity, not even for 2 Strings. Instead, you should use string interpolation. Example:

#set ($string = "exp")
#set ($number = 1)
#set ($interpolatedExample1 = "$string$number")
#set ($interpolatedExample2 = "${string}someStringLiteral$number")

Read more details and examples in the documentation.

like image 195
Eduard Moraru Avatar answered Oct 27 '25 10:10

Eduard Moraru



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!