留言板

How to pass a value in the url to read in a template?

Alberto Fernadez,修改在13 年前。

How to pass a value in the url to read in a template?

Junior Member 帖子: 49 加入日期: 09-5-6 最近的帖子
I've been fighting with this for a while. I have rad a bunch of posts and wiki pages and I still can not figure out how to do it. Let me explain what I've tried.
I'm trying to use a parameter in the url to change some aspects of how an article is displayed. The idea that I had was to add to the url something like ?view=detail
In the template I had tried:

$request.getParameter('view'))
$request.get('attributes').get('view')
... and anything that I found around.
I can get the url by $request.attributes.CURRENT_URL with no problem and I see that ?view=detail is there but it does not show as an attribute, parameter, or anything else, only in the url.
Is this imposible to do by just appending the parameter to the naked url of the page?
I'm just starting with this so maybe I'm doing it all wrong.
Any help would be much appreciated
thumbnail
Amos Fong,修改在13 年前。

RE: How to pass a value in the url to read in a template?

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
Hi Alberto,

I just tested it and it worked ok. It should be:

$request.getParameter("view")


If you're in a web content template where the request isn't available I do this to workaround it:

#set ($currentURL = $request.get("attributes").get("CURRENT_URL"))

#set ($value = $httpUtil.getParameter($currentURL, "paremeter", false))
Alberto Fernadez,修改在13 年前。

RE: How to pass a value in the url to read in a template?

Junior Member 帖子: 49 加入日期: 09-5-6 最近的帖子
Thank you so much. I got it working by using string utils and split and... Ugly.
This way it is just clean and understandable. I just changed to use it. Works like a charm.
Amos, if you do not mind allow me to ask something else. If the request is not available in a content template shouldn't $request show nothing? Or is it that is not available completely?
thanks
thumbnail
Amos Fong,修改在13 年前。

RE: How to pass a value in the url to read in a template?

Liferay Legend 帖子: 2047 加入日期: 08-10-7 最近的帖子
if you are in the web content template, you do have a $request variable it's just not the regular HttpServletRequest. But you can still see the contents of it just by putting "$request" in your template.

see the CMS Section in the wiki about request: http://www.liferay.com/community/wiki/-/wiki/Main/Access+Objects+from+Velocity
Alberto Fernadez,修改在13 年前。

RE: How to pass a value in the url to read in a template?

Junior Member 帖子: 49 加入日期: 09-5-6 最近的帖子
Thank you Amos,

I had read that. I guess what I did not understand was that parameters passed un the url were passed to HttpServletRequest. I do not have this kind of deep knowledge about liferay treatment of html request and so on. Getting better thought emoticon