Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a structure field value in a display template script

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.

like image 805
Mark Avatar asked May 15 '26 02:05

Mark


2 Answers

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.

like image 84
EpicFailv2 Avatar answered May 16 '26 16:05

EpicFailv2


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

like image 32
Tina Agrawal Avatar answered May 16 '26 16:05

Tina Agrawal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!