2

I'm trying to put in place a customized display for my Asset Publisher Entries. I created a Structure with an "image" field (named "main_image") and then, I created a display template to get the entries :

<#if entries?has_content>
    <#list entries as curEntry>
            <div>${curEntry.getTitle(locale)}</div>
        </#if>
    </#list>
</#if>

The problem is that I don't know how to get the image field ("main_image" declared in the structure) value.

I tried this with no success :

<img src = "${curEntry.main_image()}"</img>

Regards,

Mark.

Mark
  • 21
  • 1
  • 2

3 Answers3

3

Old as heck question, but google still showed this to me so i'll share my research; mashup of how i get structure fields in ADT it:

<#if entries?has_content>
    <#assign layoutLocalService = serviceLocator.findService("com.liferay.portal.kernel.service.LayoutLocalService")>
    <#list entries as entry>
        <!-- get field values for entry -->
        <#assign fields = entry.getAssetRenderer().getDDMFormValuesReader().getDDMFormValues().getDDMFormFieldValues()/>

        <!-- print simple text field -->
        <div>${fields[1].getValue().getString(locale)}</div>

        <!-- link to page structure field -->
        <#assign linkMap = fields[2].getValue().getString(locale)?eval />
        <#assign pageURL = layoutLocalService.getLayout(linkMap.groupId?number, linkMap.privateLayout, linkMap.layoutId?number).getFriendlyURL() />
        <a href="${pageURL}" class="hidden"><span class="link"></span></a>

        <!-- document structure field -->
        <#assign docValJSON = fields[6].getValue().getString(locale) /> 
        <#if docValJSON?length gt 0 >
            <#assign docVal = docValJSON?eval />
            <a href="/documents/${docVal.groupId}/0/${docVal.title}">download</a>
        </#if>
    </#list>
</#if>

Note that link is expected to always be present so no extra check like with the document. Just FYI "serviceLocator" needs to be enabled in portal settings, otherwise - error.

EpicFailv2
  • 29
  • 1
  • 4
  • 1
    Hoooly shiz take my upvote. This took waaaaaaaay too long to figure out. Liferay docs are just ridiculously useless – halpdoge Apr 17 '18 at 18:39
1

I think what you are trying to do is access a web content structure from a asset publisher display template. You cant do it the way you have mentioned.

You will have to parse the xml and then do it.

This link will help you - Accessing a Web Content Structure from Application Display Template

Tina Agrawal
  • 616
  • 9
  • 16
-1

If I remember correctly, the interface method is called getData(). You can find out by yourself if you temporarily insert ${curEntry.getClass().getName()} into your template and then look up the interface that you'll see in the output.

Answering to your comment: The attributes typically are transparently resolved, e.g. try ${curEntry.main_image.getClass().getName()}, ${curEntry.main_image.getData()}. (This is all from memory - I didn't need this in a while. Try variations of these if it still doesn't work, or reply back.

Also note that you have a weird </#if> in your template. I assume that it's a leftover from cleaning up the code for this question, otherwise you might want to correct that as well.

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • 1
    Hi Olaf. It outputs : `com.liferay.portlet.asset.model.impl.AssetEntryImpl`. But, which attribute in this class (or super class) is holding the structure custom field ("main_image") ? I looped through `curEntry.getExpandoBridge().getAttributeNames()` but nothing in the output. – Mark Sep 17 '14 at 06:54
  • 1
    This still does not work. If you add a custom entry to the content structure, you cannot get to it in ADT as ${entry.customFieldName.getData()}. – halpdoge Apr 17 '18 at 18:16