簡體   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