Abinash Koirala Abinash Koirala - 1 year ago 73
Java Question

Escaping the dollar sign in velocity using backslash not working

I have the following segment to get rendered from a velocity template file.

xyz $$foo

The dollar signs need to be escaped from VTL parser. And in the template file I represented it as

xyz \$\$foo

I expect

xyz $$foo

but I get

xyz \$foo

What am I doing wrong??

Answer Source

One of the way is to use a fixed string variable i.e, setting a variable for the $ sign and then using it.

#set ( $d = "$")
xyz ${d}${d}foo

It gives the expected output

xyz $$foo