4/05/2011

Tutorial: How to enhance the Liferay Asset Publisher

Have you ever wondered how you could change the asset publisher to (for example) also display the ratings of the assets you show? Have you ever tried to display more meta data of the documents you display ? In Liferay, this is controlled by the display styles of the asset publisher. You need to create your own display style to change how the asset publisher renders its output.


Today we will enhance the Asset Publisher to provide us more ways to display the data retrieved!


Register new display style


First, you need to allow the User to choose a new display style. The standard styles are table,title-list,abstracts and full-content. To add a new one, add the following line to your portal-ext.properties in your ext:


asset.publisher.display.styles=table,title-list,abstracts,full-content,your-display-style


Next, add the following line to your language.properties (in a hook, for example): 


your-display-style = Name Of Your Display Style


This makes sure, that you can internationalize your titles and the user has something meaningful to read.


Create a Hook for the asset publisher


The last step is to create a JSP in a hook for the asset publisher that formats the display of the assets the way you want. So let the Liferay IDE create a hook for you and add the following to your liferay-hook.xml: 


<custom-jsp-dir>/META-INF/custom_jsps</custom-jsp-dir>


Now, rebuild the directory structure for the asset publisher in your custom JSP dir: html / portlet / asset_publisher / display.


Put a JSP called your_display_style.jsp into this directory. This is the file, that will be called when a User selects your new display style. 


I think it would be the best, if you just copied an existing one, to see how the iteration over the asset entries is done. You can then adopt it the way you like.




If you like this tutorial it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.