如何让 Velocity 输出大于/小于而不转义?

发布于 2024-08-27 19:24:15 字数 365 浏览 6 评论 0原文

我试图让 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 技术交流群。

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

发布评论

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

评论(3

数理化全能战士 2024-09-03 19:24:15

这不是默认行为,我能想到发生这种情况的唯一原因是,如果您在 velocity.config 中配置了 EscapeHtmlReference 事件 ReferenceInsertionEventHandler 或在 Velocity 初始化代码中。

这是有关事件的更多信息

It is not a default behavior, the only reason I can think of why this is happening is if you have event ReferenceInsertionEventHandler configured with EscapeHtmlReference either in your velocity.config or in the Velocity initialization code.

Here is more info about events

无畏 2024-09-03 19:24:15

我对 Velocity 也有同样的问题 - 但是,问题是我使用 Velocity 作为第三方嵌入式语言,并且无权更改 Velocity 设置。

不幸的是,我能找到的唯一解决方案是重写代码而不显式使用大于/小于,这无疑是可怕的,但这都是为了让它工作......

这是您正在尝试的条件的示例解决方法查看一个数字是否大于另一个数字:

if (n1 > n2) //Doesn't work because velocity turns this into if (n1 > n2)

if (n1 != n2)
{
    diff = n1 - n2;
    abs = abs(n1 - n2);
    if (diff / abs == 1) //Greater than
    else //if == -1 then less than
}
else //Equal

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:

if (n1 > n2) //Doesn't work because velocity turns this into if (n1 > n2)

if (n1 != n2)
{
    diff = n1 - n2;
    abs = abs(n1 - n2);
    if (diff / abs == 1) //Greater than
    else //if == -1 then less than
}
else //Equal
柳若烟 2024-09-03 19:24:15

也许您可以使用此处描述的备用符号:

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).

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