cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving the content of a given folder in a .ftl script

theorbix
Confirmed Champ
Confirmed Champ
Hello, I'm stuck in trying to do something that should be fairly simple…

I'm writing a dashlet that should list all the documents in a given space.

I've started writing the .ftl script that should retrieve the list of documents contained in the space, but I don't know how to build the query.

The path of my space is:

/Company Home/Marketing Stuff/Whitepapers

I've tried the following, but it throws an exception:

<#list companyhome.childByNamePath["/Company Home/Marketing Stuff/Whitepapers"] as child>

I'm sure I'm doing only a stupid mistake, but the other examples of .ftl scripts that I found do not help…
2 REPLIES 2

theorbix
Confirmed Champ
Confirmed Champ
I found this useful guide: http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook

The guide contains an example that seems to fit well with my needs:

<table>
<#list companyhome.childByNamePath["/Company Home/Marketing Stuff/Whitepapers"].children as child>
   <#if child.isDocument>
      <tr><td><a href="/alfresco${child.url}" target="new">${child.properties.name}</a></td></tr>
   </#if>
</#list>
</table>

I've pasted the code in my test .ftl script, but it does not work. This is the error returned:

An error occurred in one of the dashlets.
Error during processing of the template 'Expression companyhome.childByNamePath["/Company Home/Marketing Stuff/Whitepapers"] is undefined on line 6, column 9 in alfresco/templates/foldercontent1.ftl.'. Please contact your system administrator.

theorbix
Confirmed Champ
Confirmed Champ
Ok, in case someone is wondering what was the problem… it was a mistake in the logic of my script.

It turns out that this exception:

Error during processing of the template 'Expression companyhome.childByNamePath["Company Home/Marketing Stuff/Whitepapers"] is undefined on line 6, column 9 in alfresco/templates/foldercontent1.ftl.'. Please contact your system administrator.


happens because the path name specified is invalid, or inaccessble to the user because of its ACL settings, or (and this is my case) because I added the /CompanyHome/ prefix, that is not required.

If the path specified is correct, then the childByNamePath[] method works well.

So the bottom line is that I modified my fremarker script in order to test if the folder exists before tring to list its content. Here is the correct code:

<#ftl strip_whitespace=true />
<#setting locale="it_IT"/>
<#setting datetime_format="short" />

<!– path name of the space to be listed (case sensitive, must not include the /Company Home/ prefix) –>
<#assign folderName="Marketing Stuff/Whitepapers" />

<#if companyhome.childByNamePath[folderName]?exists>
   <#assign folderObj=companyhome.childByNamePath[folderName]>
   <table>
      <tbody>
         <!– Display all documents in the space –>
         <#list folderObj.children as child >
              <tr>
                <td>${child.properties.name}
                </td>
              </tr>
         </#list>
      </tbody>
   </table>
<#else>
   <b>The space <i>${folderName}</i> does not exist…</b>
</#if>