我有结构和模板的内容,我想访问内容的标签以在模板中显示它。 在以前的Asset Publisher应用程序显示模板中,我得到了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
交换了条目,但后来收到错误:
方法public final java.util.List com.sun.proxy。$ Proxy562.getEntryTags(long)throws com.liferay.portal.kernel.exception.SystemException在com.liferay.portlet.asset上调用时引发异常。 service.impl.AssetTagLocalServiceImpl@6bc73e2b
如何在模板中使用它?
答案 0 :(得分:2)
标签使用它的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>
答案 1 :(得分:0)
从Liferay 7开始,您应该可以使用以下内容:
<#list entries as entry>
<#assign
entry = entry
/>
<#list entry.tagNames as tag>
${tag}
</#list>
</#list>