include not parsing template file

680 views Asked by At

I have three very simple files:

main.ftl

<#include "header.ftl">

<h1>Test</h1>

<#include "footer.ftl">

header.ftl

<h1>Header</h1>

footer.ftl

<h1>Footer</h1>

Technically it should output three h1's however my actual output is:

  1. I read that depending on the configuration the brackets for ftl might change from < and > to [ and ], I've tried changing but still nothing.
  2. I've used the * wildcard which checks parent directories and the current directory and still no luck.
  3. Freemarker documentation states that by default the include directive parses the content as a .ftl file so I should have no issues:

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.

So why isn't my template being parsed?

3

There are 3 answers

0
Script47 On BEST ANSWER

Turns out Freemarker wasn't processing the .ftl file as an actual .ftl file as the server was rendering the content as a .jsp file, to fix I changed:

<view-map name="frs" page="">

to,

<view-map name="frs" type="screen" page="component://ecommerce/widget/CommonScreens.xml#your-identifier"/>

which fixed the rendering. By default if the type property is not defined then it is automatically rendered a JSP file.

4
Dragomir Kolev On

From here.

<#include "/common/copyright.ftl">

So I presume the footer and header are in the same folder as your main file. So you will have to do something like:

<#include "*/header.ftl">
<#include "*/footer.ftl">
0
ddekany On

For the sake of future readers... The #include directive never outputs itself like <#include ...> (so as you now know, it's main.ftl that's not passed to FreeMarker). Its parse parameter applies to the included file. Also if a template is not found, it will throw an exception, not doing something arbitrary like printing <#include ...>.