Wednesday, July 8, 2015

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("\/"))
$renderer.getSummary($locale) 


#else


$curEntry.getTitle($locale)

$renderer.getSummary($locale)

#end
#end
#end
#end



Sunday, July 5, 2015

news slideshow in liferay 6.2


I want to insert in my portal a portlet to show news with image, description and link to that article. This portlet would be a beautiful way to get notice from readers and make the website more beautiful. But to make a new portlet takes a lot of time, why don't we use asset publisher portlet.

In liferay 6.2, we can use asset publisher template to change the way showing web content. And finally I got this:
It will automatically get image of webcontent and its description to make slideshow with beautiful transition effect. Click on the title to navigate to article. Now I will show you how to make news slideshow by asset publisher portlet:
1. Insert at least 3 article in web content. Remember that each article must has a small image, and a big image in its content to show big image and its thumb in slideshow
2. Add new asset publisher portlet. Select the categories of the articles we have added before to show content in slideshow automatically
3. Add a new template in the configuration/display setting with the code below and select it then:

##
## 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) )



$curEntry.getTitle($locale)



$renderer.getSummary($locale) 


#else


$curEntry.getTitle($locale)

$renderer.getSummary($locale)

#end
#end
#end
#end



4. Add the file css to css folder of the theme being used and import it in your custom.css:
@import url(camera.css);

5. Add images in the folder image in css folder

6. Add javascript files to javascript folder and add these code in the head of template of the theme



 
file download:
Ok it's done.
If you feel it's difficult, you can download retina liferay theme, I have add all css and javascript of the slideshow to it. You just paste the asset publisher template to use slideshow.

DOWNLOAD ATTACHMENTS:

Friday, June 26, 2015

Newest Webcontent Portlet in Liferay 6.2

Why we have to write a new portlet to display newest article in liferay while we have a powerful portlet Asset Publisher? How to make Asset Publisher show the newest article in beautiful way? It's luckily because of asset publisher template. We use asset publisher template to change the way it display and what to display. Try this template:
##
## 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())
#set($curEntry = $entries.get(0) )

#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) )



#else
#set( $image = "" )
#end 

$curEntry.getTitle($locale)




$renderer.getSummary($locale)

$curEntry.getCreateDate()




#end
#end
If you don't know how to use this tempalte, please insert new asset publisher, then choose the menu configuration, display setting tab, and choose the template. If you insert new template here, please refresh the page before choose it. I use this template for 3 asset publisher portlets in 3 columns. These articles must have small image in the abstract menu. and result here:
Hope this help you, I will give more templates in next tutorials

    Publisher Templates Code for Getting Article Small Url in liferay 6.2

    Liferay 6.2, comes with concept "Application Display Templates",  WithApplication Display Templates, you can define custom display templates used to render asset-centric applications. Let 's try simple example:
    #if (!$entries.isEmpty())  
       #foreach ($curEntry in $entries)  
         $curEntry.getTitle($locale)  
         $dateTool.format("dd MMM yyyy",  
      $dateTool.toDate("EEE, dd MMM yyyy hh:mm:ss Z", $curEntry.getPublishDate()), $locale)  
         
      
         #end  
    #end
    Thus, you can customize view of Asset Publisher portlet. This will help in getting latest news, etc. Like built in display style "Abstract" shows Article Title, abstract small image, abstract summary.
    How to get small image url and put into the application Dispaly Templates? Let's try this example:
    #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() )
    
    

    $curEntry.getTitle($locale)

    #if( $Article.getArticleImageURL($themeDisplay) ) #set( $image = $Article.getArticleImageURL($themeDisplay) )

    #else
    #set( $image = "" )
    #end


    $renderer.getSummary($locale)








    #end
    #end
    #end
     and you get this:
    You can modify more to get beautiful template to show slide news or etc
    You can get more liferay 6.2 tutorial and other free resource at liferaytheme.com.