Asset Publisher - Download Links for Documents

 Asset Publisher - Download Links for Documents


Problem: we need to make Documents and Media documents downloadable by clicking the link from Asset Publisher (using custom widget template).


Solution: use a code snippet below:


<#list entries as entry>

   <#assign entryURL = "${entry.getViewURL()}" />

   <#if entry.getAssetRendererURLDownload()??>

       <#assign entryURL = "${entry.getAssetRendererURLDownload()}" />

   </#if>
  <#-- ... -->

   <a href="${entryURL}">

      ${entry.title}

   </a>

   <#-- ... -->

</#list>

 

Explanation: the View URL entry.getViewURL() is an asset link, which is a preview link by default. If we need a download URL - we can retrieve it from the Asset Renderer using entry.getAssetRendererURLDownload(). As not all assets can be downloadable (e.g. pages) - the default View URL will be still used for them, while assets with Download URL (e.g. documents) will use the download link.


Enjoy 😏  

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration