Описание тега liferay-velocity
Velocity templates are widely used in liferay themes and dynamic web content. They allow us to segregate data(provided by user in fields retrieved from structures) and business logic which is coupled with presentation layer in template. Liferay provides various variables which can be directly used to access objects available in liferay. Service layer of liferay(along with custom user services) can be accessed within a template using serviceLocator.
Usage:
To access an element from structure with name as 'image':
<img src=$image.getData()/>
where '$' is used to access an element while getData() used to access data from the element
To use conditional statements:
#if($permissionChecker.getUserId()==10198)
$text.getData()
#end
We can use conditional logic(if,if-else,if-elseif) to check for a particular condition and use any of the default available object variable 'permissionChecker' for condition
To use loops to iterate through siblings or children of an elements:
#foreach($currentText in $text.getSiblings())
$currentText.getData()
#end
We can iterate through the repeatable elements or other elements in a structure by using a looping statements for the same.
To use service locator to access liferay/custom services
#set($userLocalService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set($user = $userLocalService.getUserById(10198)
$user
We can use serviceLocator to access Liferay/custome service in a velocity template and use methods from the same.
#set ($customPortletLocalService = $serviceLocator.findService("custom-portlet", "com.liferay.custom.service.CustomPortletLocalService"))
Further reference links: