【问题标题】:Unable to include macro file in FTL无法在 FTL 中包含宏文件
【发布时间】:2014-10-08 20:59:12
【问题描述】:

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

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

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

请建议最好的方法。

谢谢

【问题讨论】:

  • 你能发布一个你尝试过但不起作用的代码的sn-p吗?
  • 除了“不工作”之外,您还可以知道错误消息是什么。

标签: moqui


【解决方案1】:

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

webroot/screen/includes/MacroExample.ftl中创建一个宏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 将在标题中可见。这是一个正常的例子。您可以按照此步骤进行操作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-19
    • 2021-10-15
    • 2011-06-12
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多