cancel
Showing results for 
Search instead for 
Did you mean: 

Display documents with categories using Templates

aswini
Champ in-the-making
Champ in-the-making
Hi All,

I am trying to create a Presentation Template (Freemarker template) to customise my folder view. On the selected space, the custom view should show the details only for those documents that contain categories. I have written the following FTL template. But, it shows a big vacant space in my custom view. I assume its because the files in the space does not contain categories assigned to it. Can you suggest where am I going wrong please.

Thank you
Aswini



<html><head></head>
<body>
<#– Table of docs in a specific folder –>
<h3>${space.name} documents</h3>
<table cellpadding=2 border=0 style="BORDER: 1px;">
    <tr>
        <td></td>
        <td><b>Name</b></td>
        <td><b>Last Modified</b></td>
        <td><b>Categories</b></td>
    </tr>
        <#assign query = ".//*[subtypeOf('cm:content')]">
        <#list space.childrenByXPath[query] as child>
           <tr>
                    <#if child.properties["cm:categories"]?exists>
                        <td><a href="/alfresco${child.url}" target="new"><img src="/alfresco${child.icon16}" border=0></a></td>
                        <td><a href="/alfresco${child.url}" target="new">${child.properties.name}</a></td>
                        <td>${child.properties["cm:modified"]?string("dd-MMM-yyyy hh:mm")}</td>
                        <td>
                            <#list child.properties["cm:categories"] as prop>
                            ${prop.name}<br/>
                            </#list>
                        </td>
                    </#if>
            </tr>
        </#list>
</table>
</body>
</html>
4 REPLIES 4

lotharm
Champ on-the-rise
Champ on-the-rise
I think it is possible to iterate just over the direct children of a space with

<#list space.children as child>
….
</#list>

The freemarker reference page has examples http://wiki.alfresco.com/wiki/FreeMarker_Template_Cookbook#Documents_in_User.27s_Home_Space_Example

aswini
Champ in-the-making
Champ in-the-making
Thanks Lothar. That works for me, if 'Allow Categorisation' is not set for the document.

But if I allow categorisation for the document, without assigning any categories, it populates the document name with the Categories space empty in the table.

Can we change the code to show only those documents which have categories assigned to it please.

Eg: It should not look like this
Name: Demos for Training.txt
Last Modified:22 Jan 2009
Categories:


Thanks
Aswini

lotharm
Champ on-the-rise
Champ on-the-rise
Why not add a not-empty guard?
<#if child.properties["cm:categories"]?size gt 0 >

aswini
Champ in-the-making
Champ in-the-making
Wow!! - That worked.. thank you.