2

我正在尝试在 FTL 中包含一个宏文件。

根据我对框架的理解,如果我们在 xml 中包含使用标记的宏文件并在此 xml 中呈现 FTL,则定义的宏应该在 Freemarker 模板中自动可用。但这对我不起作用。

此外,我尝试通过提供绝对路径和相对路径来使用<#import>和标记将宏文件包含在 FTL 本身中。<#include>无论哪种方式都行不通。

请建议什么应该是最好的方法。

谢谢

4

1 回答 1

0

如果要在 FTL 文件中添加宏,只需在目标 FTL 文件中导入宏文件并在屏幕中渲染目标 FTL 文件。这是一个简单的例子

在中创建一个宏 FTL 文件webroot/screen/includes/MacroExample.ftl

<#macro macroExample>
   This is a macro example
</#macro>

将文件导入到Header.html.ftl

 <#import "MacroExample.ftl" as m> <#-- If the macro file in different directory you can use the relative path -->
 <@m.macroExample/>

这是通过以下代码Header.html.ftl在文件中呈现的webroot.xml

<render-mode>
     <text type="html" location="component://webroot/screen/includes/Header.html.ftl"/>
</render-mode>

现在macroExample将在标题中可见。这是一个正常的例子。您可以按照此步骤进行操作。

于 2014-10-08T04:38:44.020 回答