Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joona Vaurio
Tags in Velocity Template
October 9, 2008 1:46 AM
Answer

Joona Vaurio

Rank: New Member

Posts: 23

Join Date: July 22, 2008

Recent Posts

Hello.

I have a news page, that lists all articles with type news and on the main page I'm supposed to show some of these news. The articles on the main page are not the newest, they are picked manually, so using tags would solve this. However, I can't use asset publisher because the main page news should have a read more link to news page where the whole article is shown in a certain journal content portlet. All this is easy with velocity templates, but I can't figure out how to select the wanted articles to main page. The best way could be using a tag but I did not find any information about that. Is it possible to select articles by tag in journal velocity template?
Joshua Asbury
RE: Tags in Velocity Template
February 19, 2009 4:46 PM
Answer

Joshua Asbury

LIFERAY STAFF

Rank: Expert

Posts: 497

Join Date: September 8, 2006

Recent Posts

I'm trying to accomplish the same thing. Were you ever able to figure it out?
Thomas Kellerer
RE: Tags in Velocity Template
June 17, 2010 6:10 AM
Answer

Thomas Kellerer

Rank: Expert

Posts: 377

Join Date: June 9, 2008

Recent Posts

Joona Vaurio:
Is it possible to select articles by tag in journal velocity template?
I'm also looking for a solution to this?
Any ideas (using Liferay 5.2.3)?

Regards
Thomas
Amos Fong
RE: Tags in Velocity Template
June 17, 2010 10:03 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1898

Join Date: October 7, 2008

Recent Posts

Hi Guys,

I believe the method you're looking for is this:

1TagsAssetLocalServiceUtil.getAssets(
2    long groupId, long[] classNameIds, long[] entryIds,
3    long[] notEntryIds, boolean andOperator,
4    boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
5    int start, int end)


where entryIds is the entryId of the TagEntry. Then pass the classNameId of journal articles and you should get what you need. (This might not be the exact method parameters, I'm looking at 5.2 ee)
Petteri Torssonen
RE: Tags in Velocity Template
November 12, 2010 12:56 AM
Answer

Petteri Torssonen

Rank: New Member

Posts: 20

Join Date: February 21, 2010

Recent Posts

how about in 6.0.5? Haven't founded the way...
Alberto Fernadez
RE: Tags in Velocity Template
February 14, 2011 10:37 AM
Answer

Alberto Fernadez

Rank: Junior Member

Posts: 49

Join Date: May 6, 2009

Recent Posts

What method would we use in 6.0.5?
I have been trying to find it in the javadocs without success.
The only way I could make something similar work was by checking all articles. I'm assuming this would be very bad in terms of performace. If someone know a better way please let me know.
I could select articles by tag in 6.0.5:
 1
 2#set($AssetTagLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService"))
 3#set($JournalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
 4
 5#set ($searchTag = "TagToSearch")
 6
 7#set($articles = $JournalArticleLocalService.getStructureArticles(@group_id@,"structure"))
 8##in my case I know I want the articles that come from a certain structure but it also work with getArticles() in general
 9#foreach ( $article in $articles)
10##check if it is the latest version
11 #if ( $JournalArticleLocalService.isLatestVersion(@group_id@,$article.articleId, $article.version))
12  ##Check all tags
13  #set($articlePK = $article.resourcePrimKey)
14  #set ($tagsAsset = $AssetTagLocalService.getTagNames("com.liferay.portlet.journal.model.JournalArticle", $articlePK))
15  #foreach( $tag in $tagsAsset )
16    #if($tag == $searchTag)
17    ##Do whatever, for example
18    <p> Render article content: </p>
19    <p>uuid: $article.uuid</p>
20    <p>Title: $article.title</p>
21    <p> ------------------------------------</p>
22    #end
23  #end
24 #end
25#end


It has to be a better way
Roy Brondgeest
RE: Tags in Velocity Template
March 19, 2012 5:02 AM
Answer

Roy Brondgeest

Rank: Junior Member

Posts: 25

Join Date: January 13, 2011

Recent Posts

The right way would be to use AssetEntryQuery... but I dont think its possible to instantiate one in velocity...

Heres the Java equivalent for it:

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] anyTagIds = {tagid};
assetEntryQuery.setAnyTagIds(anyTagIds);
List<assetentry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
behnaz eslami
RE: Tags in Velocity Template
July 14, 2012 3:07 AM
Answer

behnaz eslami

Rank: Junior Member

Posts: 53

Join Date: November 13, 2011

Recent Posts

Alberto Fernadez:
What method would we use in 6.0.5?
I have been trying to find it in the javadocs without success.
The only way I could make something similar work was by checking all articles. I'm assuming this would be very bad in terms of performace. If someone know a better way please let me know.
I could select articles by tag in 6.0.5:
 1
 2#set($AssetTagLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService"))
 3#set($JournalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))
 4
 5#set ($searchTag = "TagToSearch")
 6
 7#set($articles = $JournalArticleLocalService.getStructureArticles(@group_id@,"structure"))
 8##in my case I know I want the articles that come from a certain structure but it also work with getArticles() in general
 9#foreach ( $article in $articles)
10##check if it is the latest version
11 #if ( $JournalArticleLocalService.isLatestVersion(@group_id@,$article.articleId, $article.version))
12  ##Check all tags
13  #set($articlePK = $article.resourcePrimKey)
14  #set ($tagsAsset = $AssetTagLocalService.getTagNames("com.liferay.portlet.journal.model.JournalArticle", $articlePK))
15  #foreach( $tag in $tagsAsset )
16    #if($tag == $searchTag)
17    ##Do whatever, for example
18    <p> Render article content: </p>
19    <p>uuid: $article.uuid</p>
20    <p>Title: $article.title</p>
21    <p> ------------------------------------</p>
22    #end
23  #end
24 #end
25#end


It has to be a better way


Hi
I have a problem with tags, dynamic web content and so on....
Can I send you a message and describe my problem ??
Patrizia D
RE: Tags in Velocity Template
January 23, 2013 1:43 AM
Answer

Patrizia D

Rank: New Member

Posts: 6

Join Date: April 21, 2010

Recent Posts

Hello, how can I get the url of each tag? Thanks
maryam maryam masoudy
RE: Tags in Velocity Template
January 23, 2013 2:06 AM
Answer

maryam maryam masoudy

Rank: Regular Member

Posts: 149

Join Date: October 30, 2011

Recent Posts

hi
can u explain more
do u want get query from ur asset tag ?
o r do u want get url of page?
do u want get some article or image by especial tag?
Patrizia D
RE: Tags in Velocity Template
January 24, 2013 12:56 AM
Answer

Patrizia D

Rank: New Member

Posts: 6

Join Date: April 21, 2010

Recent Posts

Hi, thanks for reply!
I want get url for every article's tag.

The code:

#set($tagdataUtil = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetTagLocalService"))
#set($listTags = $tagdataUtil.getTags("com.liferay.portlet.journal.model.JournalArticle", $journalArticle.getResourcePrimKey()))
#foreach($tag in $listTags)
<li><a href="$urlTag">$tag.getName()</a></li>
#end

I want obtain $urlTag!!!

Thanks!