Tech Tips & Tricks: tips to solve unruly Velocity problems

Welcome to another installment in our series of tips and tricks from the Polarion Software Technical Support team, in which we share solutions we provided to customers for real-world use cases that. The same tips might help you too, or others on your team. Let’s look today at a couple of things with Velocity than can be frustrating until you know the trick. 

Use Case


Get rid of the text line when variable is not defined in Velocity.

Solution


Use $!variable

The difference is what it does when ‘variable’ is not defined. In that case ‘$’ renders the whole line as if it were plain text (which is not what you want in most cases), whereas ‘$’ outputs nothing. So using ‘$’ is usually a safer option.

#set($y = $null)
Output of $!y is:
Output of $y is: $y

Use Case


Escaped special character (“) doesn’t work with Velocity.

Solution


We worked around the problem with quotes by saving the double quote character in to a variable x. (Please note the syntax ‘ ” ‘ – without spaces).
#set($test = “WI-17”)
#set($x = ‘”‘)
#set($query = “id:${x}${test}${x}”)

Output is: id:”WI-17″


Jiri Jandl is a Senior Support Engineer with Polarion Software’s European tech support team. He is based in Prague, Czech Republic.



Banner: It's all about solutions - Polarion Silver and Gold Support


Leave a Reply

This article first appeared on the Siemens Digital Industries Software blog at https://blogs.sw.siemens.com/polarion/tech-tips-tricks-tips-to-solve-unruly-velocity-problems/