cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker script: retrieve the content of a space

theorbix
Confirmed Champ
Confirmed Champ
Hello,

I'm writing a .ftl script that should retrieve the content of a certain Space.

<!– Search a given space by its unique node ID –>
<#assign folderID = companyhome.childrenByLuceneSearch["ID:workspace\\:\\/\\/SpacesStore\\/2f93b4a6-f609-11dc-a589-999071556af1"] />
<#list folderID as child>
   <#assign folderContent = child.children />
</#list>

<!– Display all documents in the space –>

<script>var AlfNodeInfoMgr = new Alfresco.PanelManager("NodeInfoBean.sendNodeInfo", "noderef");</script>
<table class="recordSet" width=100%>
   <thead>
      …
   </thead>
  
   <tbody>
      <#list folderContent as child>
          …..
      </#list>
   </tbody>
   </table>

Now I need to add a test to see if the query has found the Space or not (in case the node ID is invalid, the script would crash with the folowing error message: "An error occurred in one of the dashlets.
Error during processing of the template 'Expression folderContent is undefined on line 24, column 14 in alfresco/templates/foldercontent1.ftl.'. Please contact your system administrator.").

How can I add such a test in the script?
2 REPLIES 2

theorbix
Confirmed Champ
Confirmed Champ
In case someone was wondering… here is the solution:

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

<!– Search a given space by its pathname (warning: space name is case sensitive)  –>
<#assign folderName="Alpha Company/Marketing/Presentations" />

<#if companyhome.childByNamePath[folderName]?exists>

   <#assign folderObj=companyhome.childByNamePath[folderName]>

    <table class="recordSet" width=100%>
      
     <tbody>
             <tr>
                <td style="padding:2px;text-align:right;vertical-align:top;padding-right:1px;">
                <img src="/alfresco${child.icon16}" border=0>
                </td>
                <td style="padding:2px;text-align:left;vertical-align:top;padding-right:10px;">
                 <a href="/alfresco${child.url}" target="_blank">${child.properties.name}</a>
                  <span onclick="AlfNodeInfoMgr.toggle('${child.nodeRef}',this);">
                  <img id="browse:col1-img" src="/alfresco/images/icons/popup.gif" height="16" width="16" class="popupImage" />
                  </span>
                </td>
              </tr>
         </tbody>
   </table>
<#else>
   <b>The space "${folderName}" does not exist.</b>
</#if>

The whole trick is done using the <#if companyhome.childByNamePath[folderName]?exists> statement…

poptarts
Champ in-the-making
Champ in-the-making
Thanks Orbix. I've found it to be very useful.