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}

Share:
26,907
Sergio del Amo
Author by

Sergio del Amo

Updated on July 31, 2022

Comments

  • Sergio del Amo
    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
    Ruan Mendes over 12 years
    That's what I used when I needed it, the escape tool is kind of clunky
  • sufinawaz
    sufinawaz over 9 years
    Thomas, can you tell me where the toolbox configuration goes?
  • hudidit
    hudidit over 6 years
    I think this always works, unrelated with versions of velocity.
  • AnthonyD973
    AnthonyD973 about 2 years
    Exactly what I needed! The above code generates \n##\n though, so just use #[[##]]# if you don't want empty lines before and after the ##.