2014-09-30 75 views
2

我想在FTL中包含一個宏文件。根據我對框架的理解,如果我們在xml中使用標記包含宏文件並在此xml中呈現FTL,則定義的宏應該可以在Freemarker模板中自動使用。但這不適合我。無法在FTL中包含宏文件

此外,我試圖通過提供絕對和相對路徑來使用<#import><#include>標籤在FTL自身中包含宏文件。無論哪種方式是行不通的。

請建議什麼應該是最好的方式來做到這一點。

感謝

+0

你能發佈一段代碼,你已經嘗試過,並沒有工作嗎? – Jeroen 2014-09-30 07:52:34

+0

而不是「不工作」,你可以告訴錯誤信息是什麼。 – ddekany 2014-09-30 19:52:38

回答

0

如果你想在FTL文件添加宏剛導入目標FTL文件中的宏文件,並呈現在屏幕上的目標FTL文件。下面是一個簡單的例子

創建於webroot/screen/includes/MacroExample.ftl

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

導入宏FTL文件中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.ftlwebroot.xml文件由下面的代碼

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

現在macroExample將在標題中可見。這是一個正常的例子。你可以按照這一步來工作。