Search code examples
liferayliferay-6freemarker

Image Description in Liferay Web Content Template


In my web content structure, I have a Document and Media type field so that users can select an image. In the web content template, I want to get the selected image's description so that I can fill in the alt text for the image.

How do I go about doing getting the description information of that selected image in the template?


Solution

  • You can get fields like description, you need to first get the image ID. Then you'll use the DLFileEntryLocalServiceUtil to get the file. Once you get the file, you can call the function to get the description.

    <#assign imgID = Image.getData()?string?split("/")[5]?split("?")[0]>
    <#assign fileEntry = staticUtil["com.liferay.portlet.documentlibrary.service.DLFileEntryLocalServiceUtil"]>
    <#assign file=fileEntry.getFileEntryByUuidAndGroupId(imgID, groupId) >
    
    ${file.getDescription()}
    

    You can get the other metadata of the document/image by calling one of the other functions for the DLFileEntryModel.