Skip to content

Instantly share code, notes, and snippets.

@pavelfomin
Last active January 22, 2022 14:35
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pavelfomin/282dd597d4e88678866d to your computer and use it in GitHub Desktop.
Save pavelfomin/282dd597d4e88678866d to your computer and use it in GitHub Desktop.
Get the http request parameters in Liferay from the freemarker web content template
<#--
The request here is not the original request and doesn't contain the url query parameters
hence the usage of the serviceContext from ServiceContextThreadLocal.
-->
<#assign serviceContext = staticUtil["com.liferay.portal.service.ServiceContextThreadLocal"].getServiceContext()>
<#assign httpServletRequest = serviceContext.getRequest()>
myparam="${(httpServletRequest.getParameter('myparam')?html)!''}"
<#--
The request here is not the original request and doesn't contain the url query parameters hence the url parsing.
-->
<#assign url = request.attributes['CURRENT_URL']>
myparam = ${httpUtil.getParameter(url, "myparam", false)}
@pavelfomin
Copy link
Author

These and other Liferay tips and examples can be found at https://github.com/pavelfomin/liferay-clues

@testanull
Copy link

Very nice man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment