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.