如何创建输出两个“#”的速度模板? 行首的文字?

发布于 2024-07-15 23:11:38 字数 799 浏览 5 评论 0原文

我需要创建一个速度文档,其中一些行前缀为“## 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅浅淡淡 2024-07-22 23:11:38

使用 Velocity 上下文

${esc.h}${esc.h}

Use the Velocity context:

${esc.h}${esc.h}
·深蓝 2024-07-22 23:11:38

如果您不想添加 org.apache.velocity.tools.generic。 EscapeTool 或与您的上下文类似,您可以使用第三次尝试的稍微修改的版本:

#set($msg = "#") 
${msg}${msg} Foo this

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:

#set($msg = "#") 
${msg}${msg} Foo this
笑忘罢 2024-07-22 23:11:38

叹息......单引号和双引号之间是有区别的。 这按预期工作:

#set($msg = '##') 
$msg Foo this

打印出我想要的内容:

## Foo this

来自 Velocity用户指南

单引号将确保引用的值按原样分配给引用。 双引号允许您使用速度引用和指令进行插值,例如“Hello $name”

(我仍然困惑于为什么 \#\# 不起作用。)

Sigh....There is a difference between single quote and double quotes. This works as expected:

#set($msg = '##') 
$msg Foo this

Which prints out exactly what I wanted:

## Foo this

From the Velocity Users Guide:

Single quotes will ensure that the quoted value will be assigned to the reference as is. Double quotes allow you to use velocity references and directives to interpolate, such as "Hello $name"

(I'm still stumped as to why \#\# does not work.)

静待花开 2024-07-22 23:11:38

“##”是VTL中的单行注释分隔符,这可能是问题的开始。

## This is a comment

"##" is the single line comment delimiter in VTL, which is probably the start of your problems.

## This is a comment
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文