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??
Velocity allows for explicit escaping of References and Directives using the \ (backslash) character. If the character following the \ would start a new directive or reference, then this character is output verbatim. This can lead to some unexpected behaviour, especially with directives.
Velocity is a server-side template language used by Confluence to render page content. Velocity allows Java objects to be called alongside standard HTML. If you are are writing a user macro or developing a plugin you may need to modify Velocity content.
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
You might also want to check out the EscapeTool in velocity.
Once you have included it in context (e.g. under the name "esc"), you can use ${esc.d} to get the dollar sign. The method is you mentioned is easier for this particular case though.
I thought it was worth mentioning because it provides several other convenient methods to escape strings appropriate, if your templates are generating Java/javascript/html etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With