woensdag 28 januari 2015

How to get the current URL in a custom Liferay freemarker theme

Another one of those seemingly simple things which can be hard to find. Suppose you've created a custom theme in Liferay 6.2 based on freemarker and want to know the current URL in one of your templates. By current URL I mean the URL the user's seeing in their browser bar.

In your navigation.ftl do the following:

<#assign PortalUtil = staticUtil["com.liferay.portal.util.PortalUtil"] />

to get a referenec to the PortalUtil class then

${PortalUtil.getCurrentCompleteURL(request)}

will get you the full current URL.

It uses the implicit object $request which is available to you as one of many implicit objects; the full list can be found here

Geen opmerkingen: