How to escape a # in velocity

試著忘記壹切 提交于 2019-12-18 12:43:31

问题


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.



来源:https://stackoverflow.com/questions/53744/how-to-escape-a-in-velocity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!