Liferay Freemarker - 如何在内容模板中获取标签

Liferay Freemarker - How to get tags in a Content Template

我有一个包含结构和模板的内容,我想访问内容的标签以在模板中显示它。 在以前的资产发布者的应用程序显示模板中,我得到了带有 ServiceLocator 的标签,如下所示:

<#list entries as entry>
  <#assign assetEntryLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService") />
  <#assign assetTagLocalService = serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService") />
  <#assign assetTags = assetTagLocalService.getEntryTags(entry.getEntryId()) />
  <#list assetTags as tag>
        <#if tag.getName() != "startseite">
             ${tag.getName()}
        </#if>
  </#list>
</#list>

在我的模板中,我将条目与 .vars['reserved-article-id'].data 交换,但随后出现错误:

Method public final java.util.List com.sun.proxy.$Proxy562.getEntryTags(long) throws com.liferay.portal.kernel.exception.SystemException threw an exception when invoked on com.liferay.portlet.asset.service.impl.AssetTagLocalServiceImpl@6bc73e2b

你如何让它在模板中工作?

标签使用它的 resourcePrimKey 与 assetEntry 相关联,因此您可以这样做:

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

<#assign article = journalArticleLocalService.getArticle(getterUtil.getLong(scopeGroupId), .vars['reserved-article-id'].data)>
<#assign asset = assetEntryLocalService.getEntry('com.liferay.portlet.journal.model.JournalArticle', article.resourcePrimKey) >

<#list asset.getTags() as tag>
    <code>${tag.name}</code>
</#list>

从 Liferay 7 开始,您应该可以使用以下内容:

<#list entries as entry>
    <#assign
        entry = entry
    />

    <#list entry.tagNames as tag>
        ${tag}
    </#list>
</#list>