Escaping the dollar sign in velocity using backslash not working

Abinash Koirala picture Abinash Koirala · Mar 21, 2013 · Viewed 11.5k times · Source

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

Abinash Koirala picture Abinash Koirala · Mar 21, 2013

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