包含不解析模板文件
include not parsing template file
我有三个非常简单的文件:
main.ftl
<#include "header.ftl">
<h1>Test</h1>
<#include "footer.ftl">
header.ftl
<h1>Header</h1>
footer.ftl
<h1>Footer</h1>
技术上它应该输出三个 h1
但是我的实际输出是:
- 我读到根据配置,ftl 的括号可能会从
<
和 >
更改为 [
和 ]
,我已经尝试更改但仍然没什么。
- 我已经使用了
*
通配符来检查父目录和当前目录,但仍然没有成功。
- Freemarker 文档指出,默认情况下
include
指令将内容解析为 .ftl
文件,所以我应该没有
问题:
parse: If it is true, then the included file will be parsed as FTL, otherwise the whole file will be considered as simple text (i.e, no FreeMarker constructs will be searched in it). If you omit this option, then it defaults to true.
为什么我的模板没有被解析?
来自 here。
<#include "/common/copyright.ftl">
所以我假设页脚和页眉与您的主文件位于同一文件夹中。所以你必须做这样的事情:
<#include "*/header.ftl">
<#include "*/footer.ftl">
事实证明 Freemarker 没有将 .ftl
文件作为实际的 .ftl
文件处理,因为服务器正在将内容呈现为 .jsp
文件,为了修复,我更改了:
<view-map name="frs" page="">
到,
<view-map name="frs" type="screen" page="component://ecommerce/widget/CommonScreens.xml#your-identifier"/>
修复了渲染。默认情况下,如果 type
属性 未定义,则它会自动呈现为 JSP 文件。
为了未来的读者...... #include
指令永远不会像 <#include ...>
那样输出自己(所以你现在知道,main.ftl
没有传递给 FreeMarker)。它的 parse
参数适用于 included 文件。此外,如果未找到模板,它会抛出异常,而不是像打印 <#include ...>
.
这样的任意操作
我有三个非常简单的文件:
main.ftl
<#include "header.ftl">
<h1>Test</h1>
<#include "footer.ftl">
header.ftl
<h1>Header</h1>
footer.ftl
<h1>Footer</h1>
技术上它应该输出三个 h1
但是我的实际输出是:
- 我读到根据配置,ftl 的括号可能会从
<
和>
更改为[
和]
,我已经尝试更改但仍然没什么。 - 我已经使用了
*
通配符来检查父目录和当前目录,但仍然没有成功。 - Freemarker 文档指出,默认情况下
include
指令将内容解析为.ftl
文件,所以我应该没有 问题:
parse: If it is true, then the included file will be parsed as FTL, otherwise the whole file will be considered as simple text (i.e, no FreeMarker constructs will be searched in it). If you omit this option, then it defaults to true.
为什么我的模板没有被解析?
来自 here。
<#include "/common/copyright.ftl">
所以我假设页脚和页眉与您的主文件位于同一文件夹中。所以你必须做这样的事情:
<#include "*/header.ftl">
<#include "*/footer.ftl">
事实证明 Freemarker 没有将 .ftl
文件作为实际的 .ftl
文件处理,因为服务器正在将内容呈现为 .jsp
文件,为了修复,我更改了:
<view-map name="frs" page="">
到,
<view-map name="frs" type="screen" page="component://ecommerce/widget/CommonScreens.xml#your-identifier"/>
修复了渲染。默认情况下,如果 type
属性 未定义,则它会自动呈现为 JSP 文件。
为了未来的读者...... #include
指令永远不会像 <#include ...>
那样输出自己(所以你现在知道,main.ftl
没有传递给 FreeMarker)。它的 parse
参数适用于 included 文件。此外,如果未找到模板,它会抛出异常,而不是像打印 <#include ...>
.