问题
I have image field in structure for Web Content display:
<root available-locales="en_US" default-locale="en_US">
<dynamic-element dataType="image" fieldNamespace="wcm" indexType="keyword" name="image_1" readOnly="false" repeatable="false" required="false" showLabel="true" type="wcm-image" width="">
<meta-data locale="en_US">
<entry name="label">
<![CDATA[Image 1]]>
</entry>
<entry name="predefinedValue">
<![CDATA[]]>
</entry>
<entry name="tip">
<![CDATA[]]>
</entry>
</meta-data>
</dynamic-element>
and next template:
<#if image_1.getData()?has_content >
<div><img alt="Image 1" src="${image_1.getData()}" /></div></#if>
After I select and upload test.jpg image I only have image url like: localhost:8080/image/journal/article?img_id=10813&t=1431521227390. How can I save/get real image name (test.jpg) which was upload.
回答1:
The original name of image is not stored anywhere, so you can not get this name after uploading. The only information stored in image table are:
- imageid
- modifieddate
- type_
- height
- width
- size
Workaround might be changing type from image to documents and media, and selecting this image from portal. The URL of the document from the Document and Media library is being stored to the web content in the following format:
/documents/[doc-group-id]/0/[doc-title]/[doc-uuid]
Here is part of code which let you get original title of document
<#assign doc>
${image_1.getData()?string}
</#assign>
Title : ${doc?string?split("/")[4]}
I think this is quite good idea since, you will be not storing multiple time same image used in different articles.
回答2:
In the end I hided default file chooser. Displayed button which render click to file chooser and label which displayed text what I need.
来源:https://stackoverflow.com/questions/30215536/liferay-structure-template-get-image-name