Velocity (VM) 模板:如何禁用 jquery 块

发布于 2024-08-16 03:59:32 字数 134 浏览 5 评论 0原文

我有阿帕奇速度。 我有一些 jQuery 代码。 我认为 VM 不喜欢我做 $img.css("float","left") 之类的事情。 如何在 HTML/Javascript 块中完全禁用 VM 解析?

谢谢

I have Apache Velocity.
I have some jQuery code.
I think VM doesn't like when I do things like $img.css("float","left").
How can I completely disable VM parsing within a block of HTML/Javascript ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

时常饿 2024-08-23 03:59:32

Velocity 1.7-beta1 现已推出,并且它提供了 #[[don 't parse me!]]# 指令,因此您不必转义 .vm 文件中的一堆代码。

对我来说就像一个魅力。

Velocity 1.7-beta1 is now out, and it ships the #[[don't parse me!]]# directive, so you don't have to escape a bunch of code in your .vm files.

Works for me like a charm.

吃颗糖壮壮胆 2024-08-23 03:59:32

对于简短的示例,如上面的,如果它不是合法的 Velocity 引用,只需执行 $img,Velocity 将忽略它。

逃避引用很诱人,但这非常奇怪。如果 $img 是真实引用,则 \$img 将显示 $img。但如果 $img 不是 Velocity 引用,则 \$img 将显示 \$img。

最好的选择,特别是如果您有一个不想解析的长文本块,是将其放入单独的文件中并使用 #include,它不会解析包含文本。

#include("file.vm")

这会将“file.vm”直接包含到输出中,而不对其进行解析。 (如果您想包含文本并解析该文本,请使用#parse)。

For short examples, like the above, if it isn't a legitimate Velocity reference, just do $img and Velocity will ignore it.

It's tempting to escape the reference, but this is extremely quirky. If $img is a real reference, then \$img will display $img. But if $img is not a Velocity reference, then \$img will display \$img.

The best bet, especially if you have a long block of text you do not want parsed, is to put it in a separate file and use #include, which does not parse the include text.

#include("file.vm")

This will include "file.vm" directly into the output without parsing it. (If you want to include text and parse that text, use #parse).

最初的梦 2024-08-23 03:59:32

查看用户指南,看起来只要您速度中没有名为 $img 的变量,速度解析它应该不会有问题。否则你可以使用 \$img 进行转义。

至于实际上让解析器像使用 XML 中的 CDATA 标记一样跳过字符串,我不确定如何做到这一点。

Looking at the user guide it looks like as long as you don't have a variable named $img in velocity, you shouldn't have a problem with velocity parsing it. Otherwise you can escape with \$img.

As far as actually having the parser skip over the the string as you would with a CDATA tag in XML, I'm not sure how you could do that.

何以畏孤独 2024-08-23 03:59:32

\ 转义是不可靠的。执行:

context.put("D", "$");

然后

${D}img

在即将到来的 1.7 中,有一个新的 #[[ 解析器将完全忽略这个 ]]# 语法。希望 1.7-beta1 很快就会发布。

The \ escaping is unreliable. Do:

context.put("D", "$");

and then

${D}img

In the upcoming 1.7, there is a new #[[ parser will ignore this completely ]]# syntax. Hopefully a 1.7-beta1 will be out soon.

银河中√捞星星 2024-08-23 03:59:32

您可以在 Velocity 中转义美元符号,方法是将每个 $ 放在前面用反斜杠签名...

\$img.css("float", "left");

You can escape the dollar sign in Velocity by preceding each $ sign with a backslash...

\$img.css("float", "left");
不喜欢何必死缠烂打 2024-08-23 03:59:32

您可以分配一个变量来解析美元符号。
例如:

#set( $jQ = "$" )

现在您可以使用此变量在需要的位置放置美元符号:

<script type="text/javascript">
$jQ img.css();
</script>

请确保 $jQ 变量和 img.css(); 之间有空格> (这样速度就不会尝试将其余部分解释为不同的变量)。如果 $jQ 变量后面紧跟着括号,则不必执行此操作。

这样就可以了:

$jQ('#smithySword');

You can assign a variable to parse the dollar sign.
For example:

#set( $jQ = "$" )

Now you can use this variable to place a dollar sign where you need to:

<script type="text/javascript">
$jQ img.css();
</script>

Please ensure there's a space between the $jQ variable and the img.css(); (so that velocity doesn't try to interpret the rest as a different variable). You won't have to do this if a parenthesis follows directly after the $jQ var.

This would be fine:

$jQ('#smithySword');
秋心╮凉 2024-08-23 03:59:32

jquery 中的 $jQuery 的简写,因此您可以用 jQuery 替换任何 $

The $ in jquery is a shorthand for jQuery, therefore you can substitute any $ with jQuery

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