2016-01-15 64 views
1

我有一個結構和模板的內容,我想訪問內容的標籤以在模板中顯示它。 在資源發佈的前一個應用程序顯示模板,我的服務定位是這樣得到的標籤:Liferay Freemarker - 如何在內容模板中獲取標籤

<#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 [email protected]6bc73e2b

你如何得到這個模板的工作?

回答

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> 
0

由於Liferay的7,你應該能夠使用以下命令:

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

    <#list entry.tagNames as tag> 
     ${tag} 
    </#list> 
</#list> 
相關問題