Contanate two strings in velocity

129 Views Asked by At

I try to contanate two strings in velocity to build a html table. I want to do this e.g. like in Java with +=. Is their any possibility to do that? I can't find something.

Sourcecode looks like this, but I know that the operation += doens't work:

#foreach ($event in $allEvents)  
   #set ($longString = $longString += "<th>$event</th>")
#end

Somebody any idea how to solve that without an array?

1

There are 1 best solutions below

0
On

That would simply be:

#foreach ($event in $allEvents)  
   #set ($longString = "$!longString<th>$event</th>")
#end

Or (maybe faster):

#set($longString = '')
#foreach ($event in $allEvents)  
   #set ($longString = $longString.concat("<th>$event</th>"))
#end