Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Widget template to display images in Asset Publisher
Got a bunch of images that I added through the document and media portlet. I have tagged them so I can select them using the asset publisher. What I'd like to do is format the images a bit differently but I cannot figure out how to get the image to display in asset publisher. So I started by creating a widget template I could apply to asset publisher. I think this is about the same as an ADT so I poked around a bit and have gotten this far:
<#if entries?has_content>
<#list entries as curEntry>
<#assign entry = curEntry
assetRenderer = entry.getAssetRenderer() viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, entry)
/>
${curEntry.getTitle(locale)}
<a href="${viewURL}">
${curEntry.getTitle(locale)}
</a>
<div class="aspect-ratio aspect-ratio-8-to-3 aspect-ratio-bg-cover cover-image mb-4" > <img src="${viewURL}"></div> </#list>
</#if>This template will display the title just fine AND I can get to the image if I wrap the viewURL in a anchor tag. But I want the image directly, not through a link. I found multiple examples of how to display a journal article and a few for blogs but nothing for just an image (document). Given the flexibility of the asset publisher, my guess is that you have to determine the document type and then format it, but I can't seem to find the correct code to do this. As a bonus, I'd also like to do the same with some mp3's I'd like to present (in an audio tag) .
So I think what I need to get the path to the actual asset in the file system so it can be used in an img tag (or an audio tag when it's an mp3). Can you point me to an example that does that for images (at least). Seems easy but I can't seem to get to the right objects and methods.
<#if entries?has_content>
<#list entries as curEntry>
<#assign entry = curEntry
assetRenderer = entry.getAssetRenderer() viewURL = assetPublisherHelper.getAssetViewURL(renderRequest, renderResponse, entry)
/>
${curEntry.getTitle(locale)}
<a href="${viewURL}">
${curEntry.getTitle(locale)}
</a>
<div class="aspect-ratio aspect-ratio-8-to-3 aspect-ratio-bg-cover cover-image mb-4" > <img src="${viewURL}"></div> </#list>
</#if>This template will display the title just fine AND I can get to the image if I wrap the viewURL in a anchor tag. But I want the image directly, not through a link. I found multiple examples of how to display a journal article and a few for blogs but nothing for just an image (document). Given the flexibility of the asset publisher, my guess is that you have to determine the document type and then format it, but I can't seem to find the correct code to do this. As a bonus, I'd also like to do the same with some mp3's I'd like to present (in an audio tag) .
So I think what I need to get the path to the actual asset in the file system so it can be used in an img tag (or an audio tag when it's an mp3). Can you point me to an example that does that for images (at least). Seems easy but I can't seem to get to the right objects and methods.
Hi,For getting image url in ADT you can try
<#if entries?has_content>
<#list entries as curEntry>
${curEntry.getTitle(locale)} ---
${curEntry.getAssetRenderer().getURLImagePreview(renderRequest)}
<!--#list--> <!--#if-->
Thanks! That gave me just enough to build ADT's for both the pictures and the MP3's. Here are the complete solutions:
For the display of images in an Asset Publisher:
For the display of playable MP3 in an Asset Publisher:
Pretty much covers it! I still need to add a bit more formatting but I really appreciate the tip. Got me moving forward again.
For the display of images in an Asset Publisher:
<#if entries?has_content>
<#list entries as curEntry>
<#assign entry = curEntry
assetRenderer = entry.getAssetRenderer()
imgPreview = assetRenderer.getURLImagePreview(renderRequest)
/>
${curEntry.getTitle(locale)}
<div class="cover-image">
<img src="${imgPreview}">
</div>
<!--#list-->
<!--#if-->
For the display of playable MP3 in an Asset Publisher:
<#if entries?has_content>
<#list entries as curEntry>
<#assign entry = curEntry
assetRenderer = entry.getAssetRenderer()
mediaFile = assetRenderer.getURLDownload(themeDisplay)
/>
${curEntry.getTitle(locale)}
<div>
<audio controls>
<source src="${mediaFile}" type="audio/mpeg">
</audio>
</div>
<!--#list-->
<!--#if-->
Pretty much covers it! I still need to add a bit more formatting but I really appreciate the tip. Got me moving forward again.
<#assign imageMimeTypes = propsUtil.getArray("dl.file.entry.preview.image.mime.types") catagory = "" filterApplied = false /> <#if entries?has_content> <#list entries as entry> <#if imageMimeTypes?seq_contains(entry.getMimeType())> ${dlUtil.getPreviewURL(entry, entry.getFileVersion(), themeDisplay, "")} </#if> <h2 class="text-center">${entry.title}</h2> <h2 class="date mx-2 text-center">${entry.createDate}</h2> </#list> </#if>
I have created successfully created images with preview.