Liferay Dynamic Data Lists: How to get image URL?

2019-09-09 21:04发布

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?

2条回答
够拽才男人
2楼-- · 2019-09-09 21:56

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>
查看更多
放我归山
3楼-- · 2019-09-09 22:00

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.

查看更多
登录 后发表回答