Liferay Dynamic Data Lists: How to get image URL?

时光毁灭记忆、已成空白 提交于 2019-12-12 04:37:38

问题


I am creating a custom template in velocity for a Dynamic Data Lists and I want to get the image URL for the selected image. How can I get it?

The code is:

#set ( $DDLRecordService =  $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService") )
#set ( $records = $DDLRecordService.getRecords($mathTool.toNumber($reserved_record_set_id)) )

#foreach ($record in $records)
    #set( $fields = $record.getFields() )
    #set( $URL = $fields.get("URL").getValue() )
    #set( $Link = $fields.get("Linktitle").getValue() )
    #set( $Preview = $fields.get("Vorschaubild").getValue() ) ##the image is here

    $URL
    $Link
    $Preview
#end

The $preview output is: {"groupId":"0000000","uuid":"ccdaccec-00a0-4284-a000-589be48‌​99281","version":"1.‌​0"}

Any suggestion?


回答1:


Itt will work if you replace UUID_HERE to the real UUID.

<a href='${themeDisplay.getPortalURL()}/c/document_library/get_file?uuid=UUID_HERE&groupId=${themeDisplay.getScopeGroupId()}'>MyFile OR Image</a>



回答2:


I also came across similar situation and after searching on the internet for hour(s), didn't find any useful information apart from LPS-34792 ticket.

Well, you can render image on the UI from a Documents and Media field using:

<#assign hasPicture = cur_record.getFieldValue("picture")?has_content>

<#if hasPicture>
    <#assign picture = jsonFactoryUtil.createJSONObject(cur_record.getFieldValue("picture"))>
    <img src='/documents/${picture.getString("groupId")}/${picture.getString("uuid")}' />
</#if>

Where picture is the name of field and hasPicture will check if the image was selected.



来源:https://stackoverflow.com/questions/39611033/liferay-dynamic-data-lists-how-to-get-image-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!