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

edgar
Champ in-the-making
Champ in-the-making
Hi,

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

see this forum thread for more information: http://forums.alfresco.com/viewtopic.php?t=6111&highlight=include and especially this JIRA issue: http://issues.alfresco.com/browse/WCM-399

cheers,

Edgar

nyronian
Champ in-the-making
Champ in-the-making
Thank you for your response Edgar.

I still don't see a way for it to work.  The file I am trying to reference is another ftl in the repository. 

So let me show you what I am doing….

I have a header.ftl that needs to be included in the top of another ftl file.  I can access the header.ftl with the following code:


<#assign header = companyhome.childByNamePath["Data Dictionary/Presentation Templates/RoofHeatTemplates/header.ftl"]  >

That gives me access to the file node.

I then need to run a 
<#include "header.ftl" >
in the main ftl file.

It seems that whatever I put in for the path name to the header.ftl, it doesn't find it.

I have tried: ${header.nodeRef}, ${header.url} and ${header.displayPath}, each one gives me an error. 

For example ${header.nodeRef} gives the following error:

org.alfresco.error.AlfrescoRuntimeException: Error during template servlet processing: Error during processing of the template 'Error reading included file workspace://SpacesStore/90568487-f768-11db-a73d-7b34ccb063d2/header.ftl'. Please contact your system administrator.
caused by:
org.alfresco.service.cmr.repository.TemplateException: Error during processing of the template 'Error reading included file workspace://SpacesStore/90568487-f768-11db-a73d-7b34ccb063d2/header.ftl'. Please contact your system administrator.
caused by:
freemarker.template.TemplateException: Error reading included file workspace://SpacesStore/90568487-f768-11db-a73d-7b34ccb063d2/header.ftl
caused by:
java.io.FileNotFoundException: Template workspace://SpacesStore/90568487-f768-11db-a73d-7b34ccb063d2/header.ftl not found.

The unit test only show the included templets sitting in the filesystem, not in the repository.  Also, I am not using the AVM, just strictly alfrescos web-client Template Processor.

Thanks again.

mikef
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.

nyronian
Champ in-the-making
Champ in-the-making
PERFECT!!!  Thank you so much!

I was doing a screwed up syntax of:

<#assign FLTFile= companyhome.childByNamePath["file.ftl"]  >
<#include "${FLTFile.nodeRef}" >

instead of the proper syntax of:

<#include FLTFile.nodeRef >

edgar
Champ in-the-making
Champ in-the-making
Hi,

Can I also use constructs like companyhome.childByNamePath in my XSL templates? If so: is there an example of this somewhere?

The Template Guide seems to be geared towards Freemarker instead of XSLT?

cheers,

Edgar

kevinr
Star Contributor
Star Contributor
No, the model available in XSL is very different to the rich freemarker model - however we are working towards a common model.

Thanks,

Kevin

nyronian
Champ in-the-making
Champ in-the-making
Is it just me or is managing the Freemarker data model and transformations SO much simpler and more flexible than XSLT?  I am tasking myself to see if I can duplicate what I am doing in Freemarker to XSLT and I don't see ways to do things like the default model information shown at

http://wiki.alfresco.com/wiki/Template_Guide_For_Alfresco_1.4_and_2.0#Default_Model

Are there ways to make companyhome, userhome, person, args, session, etc. etc. available in an xstl transformation?  More over, what about the items in the TemplateNode class and the ability to add our own HashMaps and beans that become available on the model. 

I am new to XSLT transformations but I am looking and looking for a way to make these items available to an XLST transformation and I beleive I am missing something.  As popular as it is, I can't beleive there is no way to do this.  The Freemarker manual describes very clearly and simply how to do it, I can find no such things for the XSLT model.  Is there a keyword or term they use I am missing.

I did look at the XSLTRenderingEngine class in alfresco and see an invokeMethod class but I don't see examples anywhere on how to use it.  Is there where you put all these custom methods?

Sorry to ramble on for what may be a simple question, if anyone can simply point me in the right direction, I can figure it out….

Thanks!

davidc
Star Contributor
Star Contributor
Are you saying that XSLT is easier and more flexible than Freemarker?

nyronian
Champ in-the-making
Champ in-the-making
No, I am saying I understand Freemarker and how to expose all this extra data to it, but I do not see how to do it in XSLT.  In Freemarker, you simply tie a bean to the data model and it is available in the transformation.  Very simple.  But I would like to figure out how to expose beans in XSLT i.e. args, company_home, the TemplateNode class, my own Beans, etc. etc.  I assume XSLT can do the same things,  that is, somehow tie a javabean and expose it in the data model.  Am I right?

I have been looking through quite a bit of XSLT information and it is not clear to me how to do it.  Maybe they have a completly different concept?