2

I am trying to include a macro file in the FTL.

As per my understanding with the framework, if we include the macro file using tag in the xml and render a FTL in this xml, the defined macros should be automatically available in Freemarker template. But this is not working for me.

Also, I have tried to include the macro file in FTL itself using <#import> and <#include> tag, by providing absolute and relative path both. Either way is not working.

Please suggest what should be the best possible way to do it.

Thanks

1 Answers1

0

If you want to add a macro in the FTL file just import the macro file in the destination FTL file and render the destination FTL file in the screen. Here is a simple example

Create a macro FTL file in the webroot/screen/includes/MacroExample.ftl

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

Import the file in the Header.html.ftl

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

This Header.html.ftl is rendered in the webroot.xml file by the following code

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

Now the macroExample will be visible in the Header. This is a normal example. You can follow this step to work your.

Deb
  • 2,922
  • 1
  • 16
  • 32