How to escape a # in velocity

2019-02-05 10:27发布

问题:

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:

## 

回答1:

this:

#[[
##
]]#

will yield:

##

anything within #[[ ... ]]# is unparsed.



回答2:

If you don't want to bother with the EscapeTool, you can do this:

#set( $H = '#' )
$H$H


回答3:

Maybe, the following site helps? http://velocity.apache.org/tools/1.4/generic/EscapeTool.html



回答4:

Add the esc tool to your toolbox and then you can use ${esc.hash}



回答5:

${esc.h} will output # as per

this link



回答6:

The set technique is a good way to get around any characters you need escaping, like if you want to have $name followed by "_lastname" then you can do:

set ($n = '_lastname)

and have this in your template:

$name$n

and it's all good.



标签: velocity