Search code examples
liferayliferay-6

Web content display all files in document library


I'm trying to use a Web content Display to show all the files in a particular folder of document library.

I would like to keep customize the choice of the folder.

Do you know if exist a dynamic element in template that point to a folder not to a specific field in the document library?

If is not possible someone know a different way to do that?

thanks in advance

Sabrina


Solution

  • You can create structure that holds text field for folderId named "folderId".

    Than create template

    #set($service = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService"))
    #set($gid = $getterUtil.getLong($request.get("theme-display").get("scope-group-id")))
    #set($fid = $getterUtil.getLong($folderId.getData()))
    
    #set($files = $service.getFileEntries($gid, $fid))
    
    #foreach($doc in $files)
        #set($uet = $httpUtil.encodeURL($htmlUtil.unescape($doc.getTitle())))
        <a href="/documents/$gid/$fid/$uet">$doc.getTitle()</a><br />
    #end
    

    Create article by that template/structure and enter folder id that you want to display. Add "Web content display" portlet that displays this article.

    UPDATE:

    For Liferay 6.1 method signature was changed and is

    List<DLFileEntry>   getFileEntries(long groupId, long folderId, int start, int end, OrderByComparator obc) 
    

    So for liferay 6.1 you should change call to be at least

    #set($files = $service.getFileEntries($gid, $fid, -1, -1, null))
    

    or change for start/end/sort.