在Velocity中包含文字JSON内容(避免HTML转义)

问题描述 投票:4回答:2

我正在尝试使用Atlassian产品中嵌入的Velocity引擎(并通过com.atlassian.templaterenderer公开)将JSON值替换为模板。

在模板中,这看起来有点像以下内容:

<script>
  foo = $foo
</script>

但是,当我使用映射到字符串["bar", "baz"]的“foo”渲染模板时,输出如下:

<script>
  foo = [&quot;bar&quot;, &quot;baz&quot;]
</script>

如何避免这种情况?

velocity vtl
2个回答
5
投票

Atlassian有一个事件处理程序,它对名称不以WithHtml结尾的任何变量执行转义。

从而:

<script>
foo = $fooWithHtml
</script>

根据需要扩展。


1
投票

这不是默认行为,看起来你在EscapeHtmlReference或java初始化中注册了velocity.properties事件处理程序。有关事件处理程序here的更多详细信息。

© www.soinside.com 2019 - 2024. All rights reserved.