cancel
Showing results for 
Search instead for 
Did you mean: 

#include directive

nyronian
Champ in-the-making
Champ in-the-making
I can't, for the life of me, get the #include directive to work within a freemarker "Presentation Template"

Does anyone know if it is supported or what the "file name" is supposed to look like.  I have tried as many configurations of the filename that I can think of and continually get "FileNotFound" exception.

Any help would be appreciated.  Thank you in advance.

Jim
21 REPLIES 21

davidc
Star Contributor
Star Contributor
XSLT transforms XML documents.  So, it's not natural to provide arbitrary Javabeans as source data.

Potentially, custom XSLT functions could be implemented and registered to perform this kind of binding, but this is really outside of XSLT's natural support.

All I can suggest is to search the web to see if folks have attempted the same.  It's not an area I'm too familiar with.

jeff
Champ in-the-making
Champ in-the-making
Hi folks,

We are running 2.2 and I am now having problems with the freemarker include directive.  After many many tries and incarnations of trying to include a file, I've resorted to the most simple form I know.  Here is a snippet of the FTL file:

<#assign FTLfilename = "navglobal01.ftl"/>
<#include "${FTLfilename}">

However, after editing the desired asset I get the following error:

Please correct the errors below then click Finish.

    * error regenerating rendition using freemarker-include-file.ftl: freemarker.template.TemplateException: Error reading included file navglobal01.ftl

navglobal01.ftl resides in the same directory as the file including it, I'd prefer it to be in an /includes folder of it's own, but I am making this as simple as possible to begin with and I still can't get it to work. 

Any ideas?

Thanks!

tommorris
Champ in-the-making
Champ in-the-making
Is that the complete message?
Sometimes the stacktrace in the error log/console has more useful info as to the cause of the problem.

nyronian
Champ in-the-making
Champ in-the-making
Here is an example of how to use an include.  Keep in mind that you are working out of a repository.

<#– Displays the contents of readme.html and/or the evaluated readme.ftl if they exist in the current space. –>

<#assign htmlFilename = "readme.html"/>
<#assign ftlFilename = "readme.ftl"/>

<#if space?exists>
    <#if space.childByNamePath["${htmlFilename}"]?exists>
        ${space.childByNamePath[htmlFilename].content}
    </#if>
    <#if space.childByNamePath["${ftlFilename}"]?exists>
        <#include space.childByNamePath["${ftlFilename}"].nodeRef>
    </#if>
</#if>

jeff
Champ in-the-making
Champ in-the-making
So I tried your suggestion and received this error after clicking next while editing a document:

Please correct the errors below then click Finish.

    * error regenerating rendition using freemarker-include-file.ftl: freemarker.core.NonStringException: Error on line 44, column 11 in freemarker_template Expecting a string, date or number here, Expression space.childByNamePath[htmlFilename].content is instead a freemarker.ext.dom.NodeListModel

while using this in the ftl template:

<#assign ftlFilename = "navglobal01.ftl"/>
<#assign htmlFilename = "navglobal01.htm"/>

<#if space?exists>
    <#if space.childByNamePath["${htmlFilename}"]?exists>
        ${space.childByNamePath[htmlFilename].content}
    </#if>
    <#if space.childByNamePath["${ftlFilename}"]?exists>
        <#include space.childByNamePath["${ftlFilename}"].nodeRef>
    </#if>
</#if>

Is it that "space" needs to be instantiated ?

thanks,

jeff
Champ in-the-making
Champ in-the-making
Here's an example of how to do it:

<#assign FTLfilename = "readme.ftl"/>
<#include space.childByNamePath["${FTLfilename}"].nodeRef>

In this case the readme.ftl is obviously in the current space context.

So I tried the above syntax for a freemarker include directive and got the following error:

Please correct the errors below then click Finish.

    * Error generating rendition using freemarker-include-file.ftl: freemarker.core.NonStringException: Error on line 41, column 11 in freemarker_template
    * Expecting a string, date or number here, Expression space.childByNamePath["${FTLfilename}"].nodeRef is instead a freemarker.ext.dom.NodeListModel

I am using Alfresco 2.2, does anyone have any ideas as to how to solve this problem?

alr
Champ in-the-making
Champ in-the-making
Hi

Here is an example of how to use an include.  Keep in mind that you are working out of a repository.

<#– Displays the contents of readme.html and/or the evaluated readme.ftl if they exist in the current space. –>

<#assign htmlFilename = "readme.html"/>
<#assign ftlFilename = "readme.ftl"/>

<#if space?exists>
    <#if space.childByNamePath["${htmlFilename}"]?exists>
        ${space.childByNamePath[htmlFilename].content}
    </#if>
    <#if space.childByNamePath["${ftlFilename}"]?exists>
        <#include space.childByNamePath["${ftlFilename}"].nodeRef>
    </#if>
</#if>

I am just tryint to to something like that in a webscript. This is some shortened dummy code, showing the problem



<#function loadNodeID nodeID>
   <#list companyhome.childrenByLuceneSearch["ID:workspace\\:\\/\\/SpacesStore\\/" + nodeID] as node>
      <#return node>
   </#list>
</#function>

<#assign freeMarkerTemplate = loadNodeID(freeMarkerTemplateID)>
${freeMarkerTemplate.nodeRef}<p>

<#include freeMarkerTemplate.nodeRef>

While the nodeRef holds perfectly valid content, which is accessible via freeMarkerTemplate.content - I cannot use the include directive without getting this error:


Message:   Error during processing of the template 'Error reading included file workspace://SpacesStore/52d1a9e5-bc4a-4ef3-826d-229fa1fa209a'. Please contact your system administrator.
   
Exception:   java.io.FileNotFoundException - Template workspace://SpacesStore/52d1a9e5-bc4a-4ef3-826d-229fa1fa209a not found.

How can the file not be found if it is there as I can read out of it? I am using Alfresco Labs v3… do I need to specify another path? I mean, the readme.html/readme.ftl example does not really look different to me.

Thanks for any help.



–Alexander

alr
Champ in-the-making
Champ in-the-making
Hello,

me again, some more information.

Stupid question: Is it possible, that you can only #include other freemarker templates if they are inside the "Web Scripts" Directory?

I had a web script in /Data Dictionary/Web Scripts/renderTemplate/ which used one of the below include directives (before that I always placed test.ftl into the right directory).

[Works] <#include "test.ftl">
[Works] <#include "../test.ftl">
[NOT WORKING] <#include "../../test.ftl">

The last one did not work, as it gave me the "File not found" error, though it was psyically definately at the right place (I was only out of the Web Scripts directory).

So, the new question is, how do I load templates inside of webscripts, which are placed in User Homes (though the readme exactly does exactly that or am I wrong)?

Thanks for any hints.


–Alexander

lee
Champ in-the-making
Champ in-the-making
Hello,

Did you ever find a solution for this?

I'm having a similar problem with the following code:
<#assign ftlFile = companyhome.nodeByReference["${nodeRef}"].nodeRef>
<#include ftlFile>

I'm getting file not found errors, though if I test the ftlFile variable (ie. without the include but just doing: ${ftlFile.content} for example, I can see the freemarker content that I want).

Here's the error:
Exception:   java.io.FileNotFoundException - Template workspace://SpacesStore/ec02892c-9cfa-410c-b6f4-b8b3a6f1ce2d not found.
   
   freemarker.template.Configuration.getTemplate(Configuration.java:489)
   freemarker.core.Environment.getTemplateForInclusion(Environment.java:1357)
   freemarker.core.Include.accept(Include.java:143)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.MixedContent.accept(MixedContent.java:92)
   freemarker.core.Environment.visit(Environment.java:196)
   freemarker.core.Environment.process(Environment.java:176)
   freemarker.template.Template.process(Template.java:232)
   org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:201)
   org.alfresco.web.scripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:396)
   org.alfresco.web.scripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:268)
   org.alfresco.web.scripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:174)
   org.alfresco.web.scripts.WebScriptRuntime.wrappedExecute(WebScriptRuntime.java:364)
   org.alfresco.web.scripts.WebScriptRuntime$1.execute(WebScriptRuntime.java:330)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:294)
   org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:209)
   org.alfresco.web.scripts.WebScriptRuntime.transactionedExecute(WebScriptRuntime.java:341)
   org.alfresco.web.scripts.WebScriptRuntime.authenticatedExecute(WebScriptRuntime.java:284)
   org.alfresco.web.scripts.WebScriptRuntime.executeScript(WebScriptRuntime.java:150)
   org.alfresco.web.scripts.WebScriptServlet.service(WebScriptServlet.java:109)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
   org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
   java.lang.Thread.run(Thread.java:595)

The file is definitely there because if I remove the include line and enter: ${ftlFile.content} I get the expected freemarker content.

I've searched all through these forums but it doesn't appear that there's an answer…. I'm using a webscript to display some html content but the ftl template to use can vary depending on a number of variables (this is the ${nodeRef} variable. Do the templates to be included need to be in a specific place? Or can I call them from any location in the repository? And if so, how?

Any help would be great. Thanks Lee

stevewickii
Champ in-the-making
Champ in-the-making
Is this functionality available in Alfresco Community 2.9.0B build 683?

For example:  <#include companyhome.childByNamePath("Data Dictionary/Web Scripts/examples/test.html.ftl").nodeRef>

I am using a webscript to process a freemarker template and write the content to a file node in alfresco.  The <#include> directive resolves to a valid nodeRef, but it throws a FileNotFoundException saying that the NodeRef cannot be found.

Here's what I'm getting for a response…

Message: Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/examples/publish.get.js': Failed to execute script 'workspace://SpacesStore//Company Home/Data Dictionary/Web Scripts/examples/publish.get.js': Wrapped org.alfresco.service.cmr.repository.TemplateException: Error during processing of the template 'Error reading included file workspace://SpacesStore/d1aa3ac7-a8ee-11dd-8d11-3d772ddcae37'. Please contact your system administrator. (AlfrescoScript#20) 
  
Exception: java.io.FileNotFoundException - Template workspace://SpacesStore/d1aa3ac7-a8ee-11dd-8d11-3d772ddcae37 not found.