How to escape a # in velocity
26,907
Solution 1
this:
#[[
##
]]#
will yield:
##
anything within #[[ ... ]]# is unparsed.
Solution 2
If you don't want to bother with the EscapeTool, you can do this:
#set( $H = '#' )
$H$H
Solution 3
Maybe, the following site helps? http://velocity.apache.org/tools/1.4/generic/EscapeTool.html
Solution 4
Add the esc tool to your toolbox and then you can use ${esc.hash}
Author by
Sergio del Amo
Updated on July 31, 2022Comments
-
Sergio del Amo almost 2 years
I would like to know how can i escape a # in velocity. Backslash seems to escape it but it prints itself as well
This:
\#\#
prints:
\#\#
I would like:
##
-
Ruan Mendes over 12 yearsThat's what I used when I needed it, the escape tool is kind of clunky
-
sufinawaz over 9 yearsThomas, can you tell me where the toolbox configuration goes?
-
hudidit over 6 yearsI think this always works, unrelated with versions of velocity.
-
AnthonyD973 about 2 yearsExactly what I needed! The above code generates
\n##\n
though, so just use#[[##]]#
if you don't want empty lines before and after the##
.