I'm new to liferay and I'm almost positive this is blazingly simple to do: Using velocity markup, I want to be able to generate links to pages within my Liferay website and embed them inside of my portlets on different pages.
I have a vague idea of how it might be done so I searched around figuring it would be posted somewhere, but I can't find anything on it. Incidentally, I want to put whatever code I come up with inside the view.jsp of the portlet. I would use velocity markup here but I don't think (don't know for sure) if that is allowed inside of a jsp.
Please let me know if you need more information to respond.
I would use velocity markup here but I don't think (don't know for sure) if that is allowed inside of a jsp.
Why would you want to use Velocity mark-up inside a JSP (view.jsp
)? I don't see any advantages in doing that apart from the argument that you are really great at velocity.
Though here is a link that would help you embed velocity inside of JSP.
Note: In my opinion it is not a good practice to embed velocity within JSP in a portlet
In JSP:
Layout
object which you can get with the help of static methods in LayoutLocalServiceUtil
.com.liferay.portal.util.PortalUtil
like getLayoutFriendlyURL
or getLayoutFullURL
etc to build the URL.In VM (these would be *.vm
files in themes):
You can follow all the same steps as mentioned in JSP. The things you would need to do that are:
Instance of LayoutLocalService
, can be found out by using the following code (taken from this answer):
#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
now you can use the velocity variable $layoutLocalService
to make calls to service methods for getting the layouts.
Then you can call methods of PortalUtil
class by using the variable $portalUtil
available for *.vm
files in themes.
You can check-out the following files for more details (if you are interested):
docroot/html/themes/_unstyled/templates/init.vm
, this contains all the velocity variables available in themes. Variables of interest might be $theme
, $theme_display
, $layout
, $navItems
.docroot/html/themes/_unstyled/templates/portlet.vm
, this file is a template to display the individual portlets.docroot/html/themes/_unstyled/templates/navigation.vm
, contains code for displaying the navigation menu with page links.docroot/html/themes/_unstyled/templates/portal_normal.vm
, this file represents a page-template in liferay and this contains the other files like navigation.vm
& portlet.vm
.