cancel
Showing results for 
Search instead for 
Did you mean: 

Include directive to include FTL in webscript's FTL

fstnboy
Champ on-the-rise
Champ on-the-rise
Hi all,

Let's see if someone can help me.

I've got a web script defined in Data Dictionary/Web Scripts Extensions/com/test

I tested the freemarker include directive with header and footer FTLs in the same directory and it works. Tested putting them somewhere else in the repository but cannot get them…

my webscript FTL looks like this:

<#assign homePageFTL = "Data Dictionary/Templates/com/homePage.ftl"/>

<#if companyhome.childByNamePath["${homePageFTL}"]?exists>
       <#include companyhome. childByNamePath["${homePageFTL}"].nodeRef />
</#if>

I'm getting the following error….
07:17:05,274  ERROR [extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 08280014 Wrapped Exception (with status template): 08280373 Error during processing of the template 'Error reading included file workspace://SpacesStore/ec225803-80ce-47ae-a033-42fd1f6719b3'. Please contact your system administrator.
org.springframework.extensions.webscripts.WebScriptException: 08280014 Wrapped Exception (with status template): 08280373 Error during processing of the template 'Error reading included file workspace://SpacesStore/ec225803-80ce-47ae-a033-42fd1f6719b3'. Please contact your system administrator.
   at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:759)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
   at org.alfresco.repo.web.scripts.RepositoryContainer$2.execute(RepositoryContainer.java:383)
   at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:381)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:436)
   at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:466)
   at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:304)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:352)
   at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:189)
   at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:118)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:58)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
   at java.lang.Thread.run(Thread.java:680)
Caused by: org.alfresco.service.cmr.repository.TemplateException: 08280373 Error during processing of the template 'Error reading included file workspace://SpacesStore/ec225803-80ce-47ae-a033-42fd1f6719b3'. Please contact your system administrator.
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:206)
   at org.springframework.extensions.webscripts.AbstractWebScript.renderTemplate(AbstractWebScript.java:590)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.renderFormatTemplate(DeclarativeWebScript.java:267)
   at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:147)
   … 24 more
Caused by: freemarker.template.TemplateException: Error reading included file workspace://SpacesStore/ec225803-80ce-47ae-a033-42fd1f6719b3
   at freemarker.core.Include.accept(Include.java:167)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:79)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.MixedContent.accept(MixedContent.java:92)
   at freemarker.core.Environment.visit(Environment.java:221)
   at freemarker.core.Environment.process(Environment.java:199)
   at org.alfresco.repo.template.FreeMarkerProcessor.process(FreeMarkerProcessor.java:202)
   … 27 more
Caused by: java.io.FileNotFoundException: Template workspace://SpacesStore/ec225803-80ce-47ae-a033-42fd1f6719b3 not found.
   at freemarker.template.Configuration.getTemplate(Configuration.java:495)
   at freemarker.core.Environment.getTemplateForInclusion(Environment.java:1490)
   at freemarker.core.Include.accept(Include.java:157)
   … 34 more

I've checked that the nodeRef shown in the error is fine, and it is.

How can I include an FTL which is in a certain path in the webscript's FTL?

Thanks
2 REPLIES 2

fstnboy
Champ on-the-rise
Champ on-the-rise
It seems that if I place the FTL inside the Data Dictionary/Web Scripts Extensions at any level I can get to it with a relative path.
Eg:

<#include "../homePage.ftl" />

But if I put it somewhere else… and I do:

<#include "../../../homePage.ftl" />

I get an error saying that the file Data Dictionary/Web Scripts Extension/com/test/../../../homePage.ftl doesn't exist….

fstnboy
Champ on-the-rise
Champ on-the-rise
Got the answer…

Alfresco uses a template processor that has a searchPath as a property (this sets where in the repository, filesystem, etc. look up for the templates). To add a custom path to that template do the following:

  • Create/Edit the custom-web-context.xml file in <TOMCAT_HOME>/shared/classes/alfresco/extension directory

  • Add a custom bean with the path you want to store the templates in as follows (I've set it to the Company Home/Data Dictionary/Templates directory):

  • <bean name="templates.store.repo.custom" parent="webscripts.repostore">
          <property name="store"><value>workspace://SpacesStore</value></property>
          <property name="path"><value>/${spaces.company_home.childname}/${spaces.dictionary.childname}/cm:Templates</value></property>
       </bean>

  • Then add another bean with the paths you want your repo to search the templates in (don't forget adding the OOTB ones!)

  • <bean id="templates.searchpath" class="org.springframework.extensions.webscripts.SearchPath">
          <property name="searchPath">
              <list>
                 <ref bean="templates.store.repo.custom" />
                 <ref bean="webscripts.store.repo.extension" />
                 <ref bean="webscripts.store.repo" />
                 <ref bean="webscripts.store.client.extension" />
                 <ref bean="webscripts.store.client" />
                 <ref bean="webscripts.enterprise.store" />
                 <ref bean="webscripts.store.alfresco" />
                 <ref bean="webscripts.store" />
              </list>
          </property>
       </bean>

  • Finally set the searchpath property of the webscripts.repo.templateprocessor with the bean we just created:

  • <bean id="webscripts.repo.templateprocessor" class="org.alfresco.repo.web.scripts.RepositoryTemplateProcessor">
          <property name="serviceRegistry" ref="ServiceRegistry" />
          <property name="freeMarkerProcessor" ref="freeMarkerProcessor" />
          <property name="searchPath" ref="templates.searchpath" />
       </bean>

  • Restart Alfresco and it should work