[英]Context merge in nested velocity templates
I have following velocity template with name exception.vm
: 我有以下速度模板,其名称为
exception.vm
:
<span class="classname">$s.getClassName().</span>
I include this in another template with name cause.vm
: 我将其包含在另一个名为
cause.vm
模板中:
#include("templates/exception.vm")
<span class="classname">$s.getCause()</span>
When I merge this with a context: 当我将其与上下文合并时:
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);
The $s.getCause()
gets interpreted properly but $s.getClassName()
does not get interpreted and prints as a literal. $s.getCause()
得到正确的解释,但是$s.getClassName()
没有得到解释,并作为文字输出。
Why is this? 为什么是这样?
Use: 采用:
#parse("templates/exception.htm")
Instead of: 代替:
#include("templates/exception.vm")
#include
includes the resource without interpreting it. #include
在不解释的情况下包含资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.