Application Display Template for Recent Message board threads
In Liferay 6.2 version, Liferay introduced a very good
feature that’s Application Display Template (ADT).
Using ADT, we can overcome creating a JSP hooks
customization in Liferay portal.
Before Liferay 6.2, If we needed to change the look and
feel of OOBT portlets like below listed,
Blogs,
Documents and Media, Wiki Map, Message Board etc.
Then we have go with JSP Hook Customization or we can’t do
the look and feel changes on fly. But Using ADT we can achieve this.
The Following portlets come with ADT functionality.
i. Asset Publisher
ii. Blogs
iii. Document and Media
iv. Categories Navigation
v. Tags Navigation
vi. Wiki
vii. Site Map
|
On the fly we can set or change look and feel of portlet
on and placed at different – different pages in site.
Suppose, our requirement is like to show message board on home page with different look and feel on Message Board than another page Message board or Same with Blogs and Wiki’s and all.
Earlier for this with Liferay we have do only by JSP Hooks
but now 6.2 onwards we can by AD. That is the power of ADT.
Message Board ADT
For example, consider Top Message Board Thread on display
on Home Page with different styling attribute like displayed in below image
shows.
|
Follow below
mentioned steps.
·
Go to Control Panel --> Sites --> Select
Site --> Configuration --> Application Display Templates
·
Click on Add --> Select Asset Publisher
Template
·
Give name Home Page Message Board ADT.
·
Select language Velocity.
Note: Application Display Template is associated with the Sites, if you want
ADT available in all sites, create ADT in Global Site.
We can add ADT in FTL as well but for
message board and this blog we using example with Velocity language.
·
Add below mentioned code. Based on
number of row we needed or pagination we can logic into velocity language but
as per my requirement I needed only 3 rows no pagination that’s why I have
putted some logic
#set($count = 0)
#if (!$entries.isEmpty())
#set
($messageBoardService = $serviceLocator.findService("com.liferay.portlet.messageboards.service.MBMessageLocalService"))
#set($messageBoardThreadService=$serviceLocator.findService("com.liferay.portlet.messageboards.service.MBThreadLocalService"))
<table class="table">
<thead>
<tr>
<th>Thread</th>
<th>Posts</th>
<th>Views</th>
<th>Last Posts</th>
</tr>
</thead>
<tbody>
#foreach
($curEntry in $entries)
#if($count
< 6)
#set($currentThread
= $messageBoardService.getMBMessage($curEntry.getClassPK()))
#set($rootMessage
=
$messageBoardService.getMBMessage($currentThread.getRootMessageId()))
#set($mBThread
= $messageBoardThreadService.getMBThread($rootMessage.getThreadId()))
#set($renderer
= $curEntry.getAssetRenderer() )
#set(
$link = $renderer.getURLViewInContext($renderRequest, $renderResponse, '') )
<tr>
<td><a
href="$link">$rootMessage.getSubject() </a> <br/> Started
by $rootMessage.getUserName() </td>
<td> $mBThread.getMessageCount() </td>
<td> $mBThread.getViewCount() </td>
<td> $currentThread.getCreateDate()
<br/> By:$currentThread.getUserName();
</td>
</tr>
#end
#set($count = $count +1)
#end
</tbody>
</table>
#end
|
· Add below mentioned property into portal-ext.properties for accessing message board services into ADT
and restart the server once.
velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
|
Based on above properties we can
access service.jar (Message board service into ADT) from velocity template not
event ADT but we can access
by Theme as well.
·
Click on SAVE button.
·
Now,
Add Asset Publisher on Particular page.
·
Go
to Configuration --> Asset Selection
--> Select Message board in assets
· Go
to Configuration --> Display Setting
--> Select created Display Template Home Page Message Board ADT.
·
Click on Save.
Comments