I need to create a velocity document that has some lines prefixed with ¨## Foo", but since the # is the velocity directive command, it is not working for me.
What I want my output document to look like:
## Foo this
## Bar that
k1, v1
k2, v2
k3, v3
Escaping has not worked out how I expected. The below does not work, obviously, as the #s are un-escaped):
## Foo this
## Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
The ## lines don't show up--again, as expected. But, my attempts at escaping do not work either. Escaping solution one:
\## Foo this
\## Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
or this, escaping solution two:
\#\# Foo this
\#\# Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
or even this...
# set($msg = "##")
$msg Foo this
$msg Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
This last one really confused me.
Any ideas?
Use the Velocity context:
${esc.h}${esc.h}
If you don't want to add org.apache.velocity.tools.generic.EscapeTool or similar to your context, you can use a slightly modified version of your third try:
#set($msg = "#")
${msg}${msg} Foo this
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