2

Liferay 7.4 stores the structure data in the "ddmfieldattribute" table. I'm trying to get the fields of the structures in the ADT template, but I can't find the solution.

The structure has the following fields:

  • title
  • content

The ADT code is as follows:

<#assign dlService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>

<#if entries?has_content>
    <#list entries as entry>
        <#if entry.getClassName() == "com.liferay.journal.model.JournalArticle" >      
            //Get the fields from the structure
        </#if>
    </#list>
</#if>

Regards!

2 Answers2

2

Not sure if I understood what you want, but you can get the Entry's Journal Article (same as Web Content) from inside a Widget Template freemarker with:

assetRenderer = entry.getAssetRenderer()
journalArticle = assetRenderer.getArticle()

and then get its structure:

articleDDMStructure = journalArticle.getDDMStructure()

and its fields:

ddmFormFields = getDDMFormFields(false)

P.S.: this github repository contains some great ADT examples

Marcos Blandim
  • 293
  • 1
  • 8
1

The code is working fine. I have managed to get the data from the "title" and "content" fields of the structure in an ADT template. (Liferay 7.4)

<#assign dlService = serviceLocator.findService("com.liferay.document.library.kernel.service.DLFileEntryLocalService")>
<#assign ddmFieldLocalService = serviceLocator.findService("com.liferay.dynamic.data.mapping.service.DDMFieldLocalService")/>

<#if entries?has_content>
    <#list entries as entry>
        <#if entry.getClassName() == "com.liferay.journal.model.JournalArticle" >      
            <#assign assetRenderer = entry.getAssetRenderer()/>
            <#assign journalArticle = assetRenderer.getAssetObject() />
            <#assign ddmStructure = journalArticle.getDDMStructure() />
            <#assign ddmForm = ddmStructure.getDDMForm()/>
            <#assign ddmFormValues = ddmFieldLocalService.getDDMFormValues(ddmForm, journalArticle.getId()) />
            <#assign ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues() />

            <#list ddmFormFieldValues as fieldName>
                <#if fieldName.getFieldReference() == 'titulo'>
                    ${fieldName.getValue().getString(locale)}
                </#if>

                <#if fieldName.getFieldReference() == 'contenido'>
                    ${fieldName.getValue().getString(locale)}
                </#if>
            </#list>
        </#if>
    </#list>
</#if>

Regards!