Fórumok

Tags in Velocity Template

Joona Vaurio, módosítva 15 év-val korábban

Tags in Velocity Template

New Member Bejegyzések: 21 Csatlakozás dátuma: 2008.07.22. Legújabb bejegyzések
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?
thumbnail
Josh Asbury, módosítva 15 év-val korábban

RE: Tags in Velocity Template

Expert Bejegyzések: 498 Csatlakozás dátuma: 2006.09.08. Legújabb bejegyzések
I'm trying to accomplish the same thing. Were you ever able to figure it out?
Thomas Kellerer, módosítva 13 év-val korábban

RE: Tags in Velocity Template

Expert Bejegyzések: 490 Csatlakozás dátuma: 2008.06.09. Legújabb bejegyzések
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
thumbnail
Amos Fong, módosítva 13 év-val korábban

RE: Tags in Velocity Template

Liferay Legend Bejegyzések: 2047 Csatlakozás dátuma: 2008.10.07. Legújabb bejegyzések
Hi Guys,

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

TagsAssetLocalServiceUtil.getAssets(
	long groupId, long[] classNameIds, long[] entryIds,
	long[] notEntryIds, boolean andOperator,
	boolean excludeZeroViewCount, Date publishDate, Date expirationDate,
	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, módosítva 13 év-val korábban

RE: Tags in Velocity Template

New Member Bejegyzések: 20 Csatlakozás dátuma: 2010.02.21. Legújabb bejegyzések
how about in 6.0.5? Haven't founded the way...
Alberto Fernadez, módosítva 13 év-val korábban

RE: Tags in Velocity Template

Junior Member Bejegyzések: 49 Csatlakozás dátuma: 2009.05.06. Legújabb bejegyzések
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:

#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


It has to be a better way
Roy Brondgeest, módosítva 12 év-val korábban

RE: Tags in Velocity Template

Junior Member Bejegyzések: 25 Csatlakozás dátuma: 2011.01.13. Legújabb bejegyzések
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);
thumbnail
behnaz eslami, módosítva 11 év-val korábban

RE: Tags in Velocity Template

Junior Member Bejegyzések: 54 Csatlakozás dátuma: 2011.11.14. Legújabb bejegyzések
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:

#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


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, módosítva 11 év-val korábban

RE: Tags in Velocity Template

New Member Bejegyzések: 6 Csatlakozás dátuma: 2010.04.21. Legújabb bejegyzések
Hello, how can I get the url of each tag? Thanks
thumbnail
maryam maryam masoudy, módosítva 11 év-val korábban

RE: Tags in Velocity Template

Regular Member Bejegyzések: 149 Csatlakozás dátuma: 2011.10.30. Legújabb bejegyzések
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, módosítva 11 év-val korábban

RE: Tags in Velocity Template

New Member Bejegyzések: 6 Csatlakozás dátuma: 2010.04.21. Legújabb bejegyzések
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!