Display asset publisher full content in another site page in liferay 6.2

We often use asset publisher to show news abstract at main page for quick view. If users want to read more, they will click on readmore link and browsers will link to the page of that article.

But I have try many times to configure asset publisher portlet, it only show full content  in the same portlet. After searching on the internet I find this, to display asset publisher full content in another site page we need to do 3 step:

1. Add asset publisher to a page and set it to default display

2. Write an article and set it default display page, here you can see the canonical URL, the unique url to an article, that will show that article in right page

3. Generate canonical URL in asset publisher by hook file or in velocity template

3.1. If you want to use hook file using eclipse:

– create hook project

– add new liferay hook configuration, select the create custom jsp and final choose the jsp override from liferay-.abstracts.jsp in asset publisher portlet.

– in this please insert the code:

viewURL = assetRenderer.getURLViewInContext(liferayPortletRequest, liferayPortletResponse, currentURL);

– deploy it and you will see the result, you can download the war here, please copy to deploy directory (liferay-portal-6.2-ce-ga4\deploy), you can install it.

3.2. If you want to generate in velocity asset publisher template, You have to use onather way. I myself use the  code bellow, like the code that we add in hook project by the variable in velocity but It does not show the right url.

$AssetRenderer.getURLViewInContext($renderRequest, $renderResponse, $currentURL)

Finally I use this code:

#set ($url1array = $currentURL.split(“\/”))

Here is the full code of newslide show asset publisher template, if you want to know more about how to make news slideshow by asset publisher, please read this article: news slideshow in liferay 6.2

## This template can be used to modify the look of a specific
## application.
## Please use the left panel to quickly add commonly used variables.
## Autocomplete is also available and can be invoked by typing “$”.

#if (!$entries.isEmpty())
#foreach ($curEntry in $entries)
#set($renderer = $curEntry.getAssetRenderer() )
#set($className = $renderer.getClassName() )

#if( $className == “com.liferay.portlet.journal.model.JournalArticle” )

#set( $Article = $renderer.getArticle() )
#if( $Article.getArticleImageURL($themeDisplay) )
#set( $image = $Article.getArticleImageURL($themeDisplay) )
#set ($content = $saxReaderUtil.read($Article.getContent()).getStringValue())
#set ($dau =$content.indexOf(‘src=”‘, 1))
#set ($dau = $dau + 5)
#set ($cuoi =$content.indexOf(‘”‘, $dau) )
#set ($urlarray = $currentURL.split(“\?”))
#set($site = $urlarray.get(0))
#set ($url1array = $currentURL.split(“\/”))


Leave a Reply

Your email address will not be published. Required fields are marked *