Thursday, February 6, 2014

Accessing Custom Liferay Services in Velocity Templates

By default we will have following property which won't allow us to use serviceLocator variable in velocity templates.

    #
    # Input a comma delimited list of variables which are restricted from the
    # context in Velocity based Journal templates.
    #
    journal.template.velocity.restricted.variables=serviceLocator

In order to access you need to change that property as below

 journal.template.velocity.restricted.variables=

Call the service in Theme as shown below.

#set ($myLocalService = $serviceLocator.findService("test-portlet", "com.test.MyLocalService"))
$myLocalService .getTestCount()
Access util class using  findUtil Method for inbuilt Util of Liferay,Shown below.

#set ($journalContentUtil = $utiLocator.findUtil("com.liferay.portlet.journalcontent.util.JournalContentUtil"))

 

No comments:

Post a Comment