How do i access GET variables as passed in the URI in a VM template?
This works only when loading the widget URL:
$request.get("parameters").get("fav").get(0)
I'm looking for a neat solution that works with friendly URLs.
Here's my testing template:
#set($url = $request.attributes.CURRENT_URL)
url: $url
#set($favs = $url.split("fav="))
favs: $favs
favs.size(): $favs.size()
#if($favs.size() > 1)
#set($fav1 = $favs.get(1).split("&").get(0))
fav1: $fav1
#else
No fav!
#end
#if($favs.size() > 2)
#set($fav2 = $favs.get(2).split("&").get(0))
fav2: $fav2
#end
#set($favs2 = $httpUtil.getParameterMap($url, "fav"))
favs2: $favs2
Fav?
Dave
Nate
Taylor
解决方案
Another option would be to use $httpUtil, a Liferay utility class that's injected in Velocity templates. This way you could do the following:
#set($url = $request.attributes.CURRENT_URL)
#set($singleValue = $httpUtil.getParameter($url, "foo", false))
#set($multipleValues = $httpUtil.getParameterMap($httpUtil.getQueryString($url)).foo)