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

Ksh*_*rma 2 java velocity

我有以下速度模板名称exception.vm:

<span class="classname">$s.getClassName().</span>
Run Code Online (Sandbox Code Playgroud)

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

#include("templates/exception.vm")
<span class="classname">$s.getCause()</span>
Run Code Online (Sandbox Code Playgroud)

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

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);
Run Code Online (Sandbox Code Playgroud)

$s.getCause()得到适当的解释,但$s.getClassName()没有得到解释和打印为文字.

为什么是这样?

Ksh*_*rma 5

使用:

#parse("templates/exception.htm")
Run Code Online (Sandbox Code Playgroud)

代替:

#include("templates/exception.vm")
Run Code Online (Sandbox Code Playgroud)

#include 包括资源而不解释它.