While dealing with Liferay theme sometime we need to access data from liferay table.
let say if we need logged in users detail inside our velocity file then in that case we need to fetch user data using user services.
Here is one example by which you can invoke liferay services from velocity file.
Let say you need logged in user's detail .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set ($userLocalService= $serviceLocator.findService("com.liferay.portal.service.UserLocalService")) | |
#set ($user = $userLocalService.getUserById($request.get("theme-display").get("user-id"))) | |
#set ($emailAddress = $user.getEmailAddress()) |
If you want to access layout details then below code may help you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set ($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService")) | |
#set ($plid = $request.get("theme-display").get("plid")) | |
#set ($layout= $layoutLocalService.getLayout($plid)) |
Note : Please ignore "." in above code.
i added just because # was creating an issue with syntax highlighter.