Using custom services or liferay services in liferay themes (velocity templates)?

前端 未结 2 1966
心在旅途
心在旅途 2021-01-06 15:31

How to use custom services method in liferay themes in velocity files like init_custom.vm, portal_normal.vm etc.

I see liferay provides a l

2条回答
  •  误落风尘
    2021-01-06 16:02

    It is possible.

    1. The following code shows how to get the services:

      // Fetching instance of my custom services
      #set ($myCustomLocalService = $serviceLocator.findService('myCustomServices-portlet', 'com.my.custom.service.MyCustomLocalService'))
      
      // Fetching instance of UserLocalServiceImpl
      #set ($userLocalService = $serviceLocator.findService('com.liferay.portal.service.UserLocalService'))
      
    2. Then simply call the service methods:

      #set ($listOfItems = $myCustomLocalService.getAllItems())
      
      #set ($listOfUsers = $userLocalService.getUsers(0, 99))
      

    For Liferay 6.1 CE GA1: I found this class VelocityVariablesImpl (see methods like insertHelperUtilities, insertVariables) which actually makes all the variables and helper utilities available to the velocity templates.

提交回复
热议问题