AnsweredAssumed Answered

Including an ftl in another ftl

Question asked by rjohnson on May 20, 2014
I have a requirement to generate some correspondence out of Alfresco. What I do is to capture the relevant metadata in special document types and then execute a processTemplate to produce some HTML output using a freemarker template.

      var docTemplate = "/Data Dictionary/Presentation Templates/Print templates/Freemarker/Letter templates/";
      docTemplate +=["fgic:icservlettertemplate"].toLowerCase();
      var template = companyhome.childByNamePath(docTemplate);
      var result = document.processTemplate(template);["fgic:icproposedresponse"] = result;

Many of these letters have "boiler plate text" in them so rather than repeating this in each template I wanted to create it once in its own freemarker template and include it in each other freemarker letter template.

There is little on the forums bout this aside from a 2008 post which I have tried to follow with no success.

So, here is what I have done, and perhaps someone can put me straight.

I have created an FTL that definitely works without an include.

In that FTL I add the line

<#assign FLTFile= companyhome.childByNamePath["Data Dictionary/Presentation Templates/Print templates/Freemarker/Letter templates/Includes/whatyoucandonow.ftl"] > <#include FLTFile.nodeRef >

This then generates an error, an excerpt from the logs is

        at freemarker.core.MixedContent.accept(
        at freemarker.core.Environment.visit(
        at freemarker.core.Environment.process(
        at freemarker.template.Template.process(
        at org.alfresco.repo.template.FreeMarkerProcessor.processString(
        … 121 more
Caused by: Template workspace://SpacesStore/4ff861be-fa1b-430b-bac9-b90873df34d1 not found.
        at freemarker.template.Configuration.getTemplate(
        at freemarker.core.Environment.getTemplateForInclusion(
        at freemarker.core.Include.accept(
        … 127 more

As you can see it claims the included node does not exist, but if you copy the noderef into the node browser it definitely does exist (see attachment).

The template has 3 lines in it

<BR />
Hello this is included
<BR />

Put simply, what am I doing wrong?