0

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 --> 
0x_Anakin
  • 3,229
  • 5
  • 47
  • 86

3 Answers3

1

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>
Marco Mercuri
  • 1,117
  • 9
  • 17
1

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>
Antonio
  • 203
  • 3
  • 10
0

Define journalArticleLocalService before use it:

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

Luã Melo
  • 113
  • 3
  • 10