Show Linked Articles In Web Content Velocity Template In Liferay

Related Assets is a feature available from Liferay 6.1 that enables you to connect an asset to other assets within the same site or to global assets.

Following code provides possibility to show linked / related articles in Liferay web content velocity template.
Sample is running with Liferay 6.2. GA3.

#set($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService" ))
#set($assetLinkLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetLinkLocalService" ))
#set($assetEntryLocalService = $serviceLocator.findService("com.liferay.portlet.asset.service.AssetEntryLocalService" ))

#set($currentArticle = $journalArticleLocalService.getArticle($getterUtil.getLong($groupId),$reserved-article-id.data))
#set($currentArticleResourcePrimKey = $currentArticle.getResourcePrimKey())
#set($currentArticleAssetEntry = $assetEntryLocalService.getEntry("com.liferay.portlet.journal.model.JournalArticle", $currentArticleResourcePrimKey))
#set($currentArticleAssetEntryEntryId = $currentArticleAssetEntry.getEntryId())
#set($currentArticleRelatedLinks = $assetLinkLocalService.getDirectLinks($currentArticleAssetEntryEntryId))

#foreach( $link in $currentArticleRelatedLinks )
   #set($linkedAssetEntryId = $link.getEntryId2())
   #set($linkedAssetEntry = $assetEntryLocalService.getEntry($linkedAssetEntryId))
   #set($linkedAssetEntryPrimaryKey = $linkedAssetEntry.getClassPK())
   #set($linkedArticle = $journalArticleLocalService.getLatestArticle($linkedAssetEntryPrimaryKey))
   #set($linkedArticleTitle = $linkedArticle.getTitle($locale))
   #set($document = $saxReaderUtil.read($linkedArticle.getContent()))
   #set($node = $document.selectSingleNode("/root/dynamic-element[@name='YourStructureItem']/dynamic-content"))
   #set($nodeText = $node.getText())
    
   ArticleTitle: $linkedArticleTitle
   NodeText: $nodeText
#end

Requirement Engineering, Business Analysis, Agile, Analysis and Design with UML, Java/J2EE, Liferay, Javascript, Embedded C++, MDD, Executable UML, Project Management


© 2017 JULIUSURBAN.NET