Fórum

Select web content by TAGs in velocity template

john belkutz, modificado 10 Anos atrás.

Select web content by TAGs in velocity template

New Member Postagens: 4 Data de Entrada: 01/10/13 Postagens Recentes
Hi all,

I'm using liferay 6.1 GA2.

What i need is select articles by tag in a web content display using a template.

Here are some codes from other posts but no one is working:

 #set ($tagsService = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsAssetLocalService"))
 #set ($tagsEntryService = $serviceLocator.findService("com.liferay.portlet.tags.service.TagsEntryLocalService"))
 #set ($journalArticleResourceService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))
 
 #set ($longGroupId = $getterUtil.getLong($groupId))
 
 #set ($tags = ["xxx"])
 #set ($entryIds = $tagsEntryService.getEntryIds($longGroupId,$tags.toArray($propsUtil.getArray(""))) )
 
#set ($notTags = [])
#set ($notEntryIds = $tagsEntryService.getEntryIds($longGroupId,$notTags.toArray($propsUtil.getArray(""))) )

#set ($classNameIds = [$portalUtil.getClassNameId("com.liferay.portlet.journal.model.JournalArticle")])
#set ($classNameIdsArray =$arrayUtil.toArray($classNameIds.toArray($arrayUtil.toArray($entryIds))) )

#set ($assets = $tagsService.getAssets($longGroupId,$classNameIdsArray,$entryIds,$notEntryIds,true,false,0,5) )

#foreach ($asset in $assets)
$journalArticleResourceService.getArticleResource($asset.getClassPK())
#end


 #set($AssetTagLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService"))
 #set($JournalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
 
 #set ($searchTag = "TagToSearch")
 
 #set($articles = $JournalArticleLocalService.getStructureArticles(@group_id@,"structure"))
 ##in my case I know I want the articles that come from a certain structure but it also work with getArticles() in general
 #foreach ( $article in $articles)
##check if it is the latest version
 #if ( $JournalArticleLocalService.isLatestVersion(@group_id@,$article.articleId, $article.version))
  ##Check all tags
  #set($articlePK = $article.resourcePrimKey)
  #set ($tagsAsset = $AssetTagLocalService.getTagNames("com.liferay.portlet.journal.model.JournalArticle", $articlePK))
  #foreach( $tag in $tagsAsset )
    #if($tag == $searchTag)
    ##Do whatever, for example
    <p> Render article content: </p>
    <p>uuid: $article.uuid</p>
    <p>Title: $article.title</p>
    <p> ------------------------------------</p>
    #end
  #end
 #end
#end


Can anyone help me please?

P.D: I have "journal.template.velocity.restricted.variables=" in my portal-ext.properties.
thumbnail
Tad Fox, modificado 7 Anos atrás.

RE: Select web content by TAGs in velocity template

New Member Postagens: 11 Data de Entrada: 19/04/12 Postagens Recentes
Realizing this is a few years old... I was wondering if you had a solution for this. I have the same problem... stuck with the same version and everything.