【问题标题】:Liferay DXP web content field inside structure结构内的 Liferay DXP 网页内容字段
【发布时间】:2018-02-13 17:45:39
【问题描述】:

您好,我创建了一个简单的结构,它只有 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 --> 

【问题讨论】:

    标签: liferay freemarker liferay-7 liferay-dxp


    【解决方案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>
    

    【讨论】:

      【解决方案2】:

      在使用之前定义 journalArticleLocalService:

      【讨论】:

        【解决方案3】:

        这个:{"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>
        

        【讨论】:

        • 这在 DXP 中失败 Failed at: #assign article = JournalArticleLocal
        猜你喜欢
        • 2011-12-15
        • 1970-01-01
        • 2013-11-15
        • 2016-05-18
        • 1970-01-01
        • 2020-05-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多