Liferay DXP web content field inside structure

2.1k Views Asked by At

Hello I've created a simple structure which only has 1 repeatable web content field. In my template I have the following code:

<#if WebContent75zf.getSiblings()?has_content>
    <#list WebContent75zf.getSiblings() as cur_WebContent75zf>
        <!-- Web Content Start -->
        ${cur_WebContent75zf.getData()}
        <!-- Web Content End -->
    </#list>
</#if>

The desired result would be either to show each web content rendered or at least get their data. What I'm getting is the following and I'm wondering if I'm doing something wrong...

<!-- Web Content Start --> 

{"className":"com.liferay.journal.model.JournalArticle","classPK":"40952"} 

<!-- Web Content End --> 
<!-- Web Content Start --> 

{"className":"com.liferay.journal.model.JournalArticle","classPK":"40971"} 

<!-- Web Content End -->
<!-- Web Content Start --> 

{"className":"com.liferay.journal.model.JournalArticle","classPK":"40990"} 

<!-- Web Content End --> 
3

There are 3 best solutions below

1
On

This: {"className":"com.liferay.journal.model.JournalArticle","classPK":"40971"} is what you need to retrieve the selected Web Content through the JournalArticleLocalService, you have just to get the classPK like this:

<#if WebContent75zf.getSiblings()?has_content>
    <#list WebContent75zf.getSiblings() as cur_webContent>
        <#assign cur_webContent_map = cur_webContent.getData()?eval>
        <#assign cur_webContent_classPK = cur_webContent_map.classPK>

        <#assign article = JournalArticleLocalService.getLatestArticle(cur_webContent_classPK?number)>

    </#list>
</#if>
0
On

Define journalArticleLocalService before use it:

<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") />

0
On

This works in Liferay 7.0. Make sure restricted variables are disabled in Liferay settings

<#-- Liferay 7.0 -->
<#-- Make sure restricted variables are disabled in Liferay settings -->

<#assign 
    serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext()
    themeDisplay = serviceContext.getThemeDisplay()
    group_id = themeDisplay.getScopeGroupId()                    
    JournalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")    
>

<#if WebContent75zf.getSiblings()?has_content>
        <#list WebContent75zf.getSiblings() as cur_webContent>
                <#assign 
                    cur_webContent_map = cur_webContent.getData()?eval
                    cur_webContent_classPK = cur_webContent_map.classPK
                    article = JournalArticleLocalService.getLatestArticle(cur_webContent_classPK?number)
                    article_id = article.articleId
                    article_content = JournalArticleLocalService.getArticleContent(group_id, article_id, null, locale, themeDisplay)
                >

                ${article_content}

        </#list>
</#if>