Search code examples
javaapidownloadliferayportal

Downloading files that has been uploaded via dynamic data list in Liferay portal


I'm uploading files via dynamic data list Document field. Now I would like to allow anonymous users to download those files, but currently they see only file name without the link to file: enter image description here

Do you have any suggestions about how can I achieve that?

Edit: As @Mark suggested, I've created Display Templated and in freemarker editor I've selected Display and Media field. It generated following code in my .ftl file:

<a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Documents_and_Media1422", locale), cur_record.getFieldType("Documents_and_Media1422"))}">

${languageUtil.format(locale, "download-x", "Documents and Media")}

</a>

I've saved changes and refreshed page. It gave me following error: Expression cur_record is undefined on line 9, column 3 in 10157#10197#16569.

Shouldn't cur_record be populated by the liferay?


Solution

  • Create new "Display Template" witch include the link to the Document:

    enter image description here

    UPDATE:

    Define the records variable:

    <#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
    <#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>
    
    <#if records?has_content>
        <#list records as cur_record>
    
           <a href="${ddmUtil.getDisplayFieldValue(themeDisplay, cur_record.getFieldValue("Documents_and_Media1422", locale), cur_record.getFieldType("Documents_and_Media1422"))}">
               ${languageUtil.format(locale, "download-x", "Documents and Media")}
           </a>
        </#list>
    </#if>
    

    Also, due to bug https://support.liferay.com/browse/LPS-43149, update the portal-ext.properties: Liferay: How to configure Liferay Portal