Iterate Node Properties in Alfresco Freemarker File

In my past projects most of the times alfresco being used in backend to store contents and front end is built using portal or other web application now whenever this kind of architecture exist there is going to be requirement where we need to expose alfresco repository to front-end system. Most of the times when we pull alfresco contents from alfresco repository through webscript based on some business logic we get list of nodeRefs or nodes.

For extracting information from this list of nodes we have two options

1)    Iterate through nodes in javascript or java controller of webscript and pass it to output ftl file.

2)    Pass list of nodes directly to ftl file and iterate through those nodes in ftl

I normally prefer second approach reason is that in that approach we could produce multiple different output formats from that list like xml,csv,json etc… which is not possible in first approach as we have already prepared that output content in javascript itself so we need to create new webscript if we want to have different output format.

Now whenever we are having list of noderef we need to extract set of properties from those nodes, Most of the times we have to deal with out-of-box properties as well as custom properties.

Here is a piece of code which you can use to iterate through all those properties in ftl file.


      <#-- Get a list of all the property names for the document -->
      <#assign props =>
      <#list props as t>
         <#-- If the property exists -->
            <#-- If it is a date, format it accordingly -->
               <tr><td>${t} = ${[t]?datetime}</td></tr>
            <#-- If it is a boolean, format it accordingly -->
               <tr><td>${t} = ${[t]?string("yes", "no")}</td></tr>
            <#-- If it is a collection, enumerate it -->
               <tr><td>${t} = <#list[t] as i>${i} </#list></td></tr>
            <#-- Otherwise treat it as a string -->
               <tr><td>${t} = ${[t]}</td></tr>

Summary: Above piece you can inject in your ftl files and it is generic enough to be reusable across different output formats.

Looking for quality Alfresco Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , , , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight


I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

Leave a Reply

Your email address will not be published. Required fields are marked *