如何创建输出两个“#”的速度模板? 行首的文字?
我需要创建一个速度文档,其中一些行前缀为“## Foo”,但由于 #
是速度指令命令,它对我不起作用。
我想要我的 输出 文档看起来像:
## Foo this
## Bar that
k1, v1
k2, v2
k3, v3
转义没有按照我的预期进行,显然,下面的内容不起作用,因为 #
没有转义):
## Foo this
## Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
## 行不工作。再次出现,正如预期的那样,但是,我的逃避尝试也不起作用。 逃避解决方案一:
\## Foo this
\## Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
逃避解决方案二:
\#\# Foo this
\#\# Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
甚至这个...
# set($msg = "##")
$msg Foo this
$msg Bar that
#foreach( $foo in $bar )
$foo.key, $foo.value
#end
最后一个真的让我感到困惑。
或者
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 Velocity 上下文:
Use the Velocity context:
如果您不想添加 org.apache.velocity.tools.generic。 EscapeTool 或与您的上下文类似,您可以使用第三次尝试的稍微修改的版本:
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:
叹息......单引号和双引号之间是有区别的。 这按预期工作:
打印出我想要的内容:
来自 Velocity用户指南:
(我仍然困惑于为什么 \#\# 不起作用。)
Sigh....There is a difference between single quote and double quotes. This works as expected:
Which prints out exactly what I wanted:
From the Velocity Users Guide:
(I'm still stumped as to why \#\# does not work.)
“##”是VTL中的单行注释分隔符,这可能是问题的开始。
"##" is the single line comment delimiter in VTL, which is probably the start of your problems.