Get url files from a folder id from documents and media in ftl template

thumbnail
Jamie Sammons, modified 3 Years ago. New Member Posts: 8 Join Date: 9/6/17 Recent Posts

Hi guys

I´m trying to show every image stored in a folder of my Documents and media library in a freemarker template DXP 7.3.

So, how can I get every file of that folder? Assuming that in the structure for that template I have a text field to put the folderId or folderUrl that I want to travel in search of it´s child files.

 

I would really appreciate any help you can offer me.

thumbnail
Gennaro Lippiello, modified 3 Years ago. Junior Member Posts: 39 Join Date: 3/9/22 Recent Posts

Take a look at method getFileEntries of the DLFileEntryLocalService

thumbnail
Jamie Sammons, modified 3 Years ago. New Member Posts: 8 Join Date: 9/6/17 Recent Posts

Thks. I´ll look into it.

thumbnail
Jamie Sammons, modified 3 Years ago. New Member Posts: 8 Join Date: 9/6/17 Recent Posts

I resolved with this code:

<#if folderId.getData()?has_content>
    <#assign groupId = themeDisplay.getScopeGroupId()/> 
    <#assign dlFileEntry = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService") /> 
    <#assign files =dlFileEntry.getFileEntries(groupId,folderId.getData()?number) >
        <#list files as item>
            <img src="${themeDisplay.getPortalURL() + themeDisplay.getPathContext() + "/documents/" + themeDisplay.getScopeGroupId() + "/" + item.getUuid()}">
                <br>
         </#list>
</#if>

Hope this get usefull to others.. 

thumbnail
Tanweer Ahmed Ansari, modified 3 Years ago. Expert Posts: 322 Join Date: 3/11/10 Recent Posts

Hi Ernesto,

Here is how we are doing it in our freemarker templates.

<#assign 
    dlAppLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLAppLocalService")
    dlFileEntryLocalService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")
	folder = dlAppLocalService.getFolder(themeDisplay.getCompanyGroupId(), 0, "FOLDER-NAME")
	fileEntries = dlFileEntryLocalService.getFileEntries(themeDisplay.getCompanyGroupId(), folder.getFolderId())
/>

 

thumbnail
Jamie Sammons, modified 3 Years ago. New Member Posts: 8 Join Date: 9/6/17 Recent Posts

Thnks for your reply!