繁体   English   中英

嵌套速度模板中的上下文合并

[英]Context merge in nested velocity templates

我有以下速度模板,其名称为exception.vm

<span class="classname">$s.getClassName().</span>

我将其包含在另一个名为cause.vm模板中:

#include("templates/exception.vm")
<span class="classname">$s.getCause()</span>

当我将其与上下文合并时:

Template tm = VelocityUtil.getTemplate("templates/cause.htm");
Context c = new VelocityContext();
c.put("s", new RuntimeException());
StringWriter sw = new StringWriter(100);
tm.merge(c, sw);

$s.getCause()得到正确的解释,但是$s.getClassName()没有得到解释,并作为文字输出。

为什么是这样?

采用:

#parse("templates/exception.htm")

代替:

#include("templates/exception.vm")

#include在不解释的情况下包含资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM