如何让 Velocity 输出大于/小于而不转义?
我试图让 Velocity 输出以下 Javascript 代码:
if ((whichOne+1) <= numCallouts ) {
whichOne = whichOne + 1; } else {
whichOne = 1;
}
每当我尝试让 Velocity 打印 > 时或a <,表示为& > >或& lt;,这对我没有帮助,因为我试图让它生成 Javascript。我已经尝试过:
#set ( $gt = ">" )
但即使这样最终也会成为 & > >
提前致谢。
I'm trying to get Velocity to output the following Javascript code:
if ((whichOne+1) <= numCallouts ) {
whichOne = whichOne + 1; } else {
whichOne = 1;
}
Whenever I try to get Velocity to print a > or a <, it represents it as a & gt; or & lt;, which doesn't help me since I'm trying to get it to produce Javascript. I've tried:
#set ( $gt = ">" )
But even that ends up as a & gt;
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这不是默认行为,我能想到发生这种情况的唯一原因是,如果您在
velocity.config 中配置了
或在 Velocity 初始化代码中。EscapeHtmlReference
事件ReferenceInsertionEventHandler
这是有关事件的更多信息
It is not a default behavior, the only reason I can think of why this is happening is if you have event
ReferenceInsertionEventHandler
configured withEscapeHtmlReference
either in yourvelocity.config
or in the Velocity initialization code.Here is more info about events
我对 Velocity 也有同样的问题 - 但是,问题是我使用 Velocity 作为第三方嵌入式语言,并且无权更改 Velocity 设置。
不幸的是,我能找到的唯一解决方案是重写代码而不显式使用大于/小于,这无疑是可怕的,但这都是为了让它工作......
这是您正在尝试的条件的示例解决方法查看一个数字是否大于另一个数字:
I've had the same issue with Velocity - however, the problem is that I was using Velocity as an third party embedded language, and didn't have access to change the Velocity settings.
Unfortunately the only solution I was able to find was to rewrite the code without using greater than/less than explicitly, which admittedly is awful, but it's all about getting it to work...
Here is an example workaround for conditionals where you are trying to see if one number is larger than another:
也许您可以使用此处描述的备用符号:
http://velocity.apache.org/engine/devel/vtl-reference-guide.html#aifelseifelse_-_Output_conditional_on_truth_of_statements
所以尝试使用
if (n1 gt n2)
。Maybe you are able to use the alternate symbols as described here :
http://velocity.apache.org/engine/devel/vtl-reference-guide.html#aifelseifelse_-_Output_conditional_on_truth_of_statements
So try to use
if (n1 gt n2)
.