O'Reilly logo

Liferay User Interface Development by Frank Yu, Xinsheng Chen, Jonas X. Yuan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Liferay services in Velocity templates

There is another powerful feature that we can use in Velocity templates: invoking Liferay services. Liferay services can be used to access a lot of resources of the portal.

For example, we will try to use the LayoutLocalService. Here is the code:

#set($layoutService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
#set($layouts = $layoutService.getLayouts($layout.getGroup().getGroupId(), false))
#foreach ($page in $layouts)
<span>$page.getName($locale) | </span>
#end

Copy this snippet of code and paste it at a convenient place in the portal_normal.vm file. When it runs, it will print out the names of all the public pages in this community. The page names will be delimited ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required