0

您好,我创建了一个简单的结构,它只有 1 个可重复的 Web 内容字段。在我的模板中,我有以下代码:

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

期望的结果是要么显示每个呈现的 Web 内容,要么至少获取它们的数据。我得到的是以下内容,我想知道我是否做错了什么......

<!-- 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 --> 
4

3 回答 3

1

{"className":"com.liferay.journal.model.JournalArticle","classPK":"40971"}是您需要通过 JournalArticleLocalService 检索所选 Web 内容的内容,您只需像这样获取 classPK:

<#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>
于 2017-09-07T10:08:47.427 回答
1

这适用于 Liferay 7.0。确保在 Liferay 设置中禁用受限变量

<#-- 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>
于 2018-07-16T16:13:12.883 回答
0

在使用之前定义 journalArticleLocalService:

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

于 2018-06-14T22:36:51.067 回答