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

stevewickii
Champ in-the-making
Champ in-the-making
I discovered that Alfresco creates a Freemarker Configuration object with the TemplateLoader set to a StringTemplateLoader when the ScriptNode.processTemplate(..) method is used to process a template, and it is set to a ClassPathRepoTemplateLoader when the TemplateTag class is used to display a template in the web client (via the Custom View for a space).  This may explain why the <#include> directive works differently, or not at all, depending upon which method you use to process a template.

This is all info for Alfresco 2.9.0B build 683.  Hopefully templates are handled consistently in Alfresco Community 3 Stable.

Cheers

lee
Champ in-the-making
Champ in-the-making
I'm using 2.2 sp1 enterprise and am having the same problems. I can't get the include directive to work if the file to include is in the repository (ie. outside of the webscript context).

If you put your webscript along with your file to include in Data Dictionary/Webscripts (or further down a hierarchy in Webscripts) you can reference the include file like this: <#include "test.ftl"> (assuming they're in the same folder)

However if I try to reference a file outside of the webscript context like this: <#include companyhome.childByNamePath["WebsiteFiles/Email Templates/Website Email Templates/News Update Template"].content >

it spits out the following error:

500 Description:    An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Error during processing of the template 'null'. Please contact your system administrator.

Exception:   java.lang.NegativeArraySizeException
   
   java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:44)
   java.lang.StringBuffer.(StringBuffer.java:92)
   freemarker.cache.TemplateCache.concatPath(TemplateCache.java:573)
   freemarker.cache.TemplateCache.acquireTemplateSource(TemplateCache.java:541)
   freemarker.cache.TemplateCache.findTemplateSource(TemplateCache.java:499)
   freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:329)
   freemarker.cache.TemplateCache.getTemplate(TemplateCache.java:229)
   freemarker.template.Configuration.getTemplate(Configuration.java:487)
   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)
   
Exception:   org.alfresco.service.cmr.repository.TemplateException - Error during processing of the template 'null'. Please contact your system administrator.
   
   org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:205)

I think you must be right in that there must be some difference in the way the templates are loaded that causes this not to work.

Can anyone shed further light on this?