我有一个包括(page1.ftl和page2.ftl)里面的一个Freemarker模板(index.ftl):春天的Freemarker呈现“包括”单独
this is the sample content on index.ftl
<#include "/pages/page1.ftl">
<#include "/pages/page2.ftl">
blablabla contents here
在我的春天环境中,我将延长类“AbstractTemplateView”和超越“renderMergedTemplateModel”方法,它调用doRender这样的:
protected void doRender(Map<String, Object> model, String viewName, HttpServletResponse response)
throws Exception {
logger.debug("start doRender");
try {
Configuration config = new Configuration();
String templatePath = templateService.getTemplateLocation();
config.setDirectoryForTemplateLoading(new File(templatePath));
Template template = config.getTemplate(viewName);
response.setContentType("text/html; charset=" + template.getEncoding());
PrintWriter out = response.getWriter();
template.process(model, out);
} catch (IOException e) {
String message = format("cannot render template <{0}> due to IOException: {1}", e.getMessage());
logger.error(message, e);
throw new NestedServletException(message, e);
}
}
我的问题是,我怎么能设置的目录包括分别针对page1.ftl和page2.ftl?可能吗 ? “setDirectoryForTemplateLoading”方法仅设置模板的默认目录。任何包括将被查找相对于此目录。
此问题的上下文是我将加载包含。但是如果我找不到包含,它会查找另一个目录。
例FTL说(index.ftl):
FREEMARKER MAIN
<#include "page1.ftl">
<#include "page2.ftl">
我试过multiloader,它似乎是工作在index.ftl。它会尝试解析到目录定义。但我怎么才能让它解析说像page1.ftl和page2.ftl不同的目录路径?可能吗?当其中一个包含不存在时,它给我提供了错误。
其部分工作。 – Arlandria