Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Current URL in velocity variable Ishan Sahore 2 de agosto de 2012 22:14
RE: Current URL in velocity variable Jignesh Vachhani 2 de agosto de 2012 22:58
RE: Current URL in velocity variable Ishan Sahore 3 de agosto de 2012 0:00
RE: Current URL in velocity variable Bart Simpson 3 de agosto de 2012 0:05
RE: Current URL in velocity variable Ishan Sahore 3 de agosto de 2012 0:32
RE: Current URL in velocity variable Jacques Traore 4 de abril de 2013 7:34
RE: Current URL in velocity variable James Falkner 4 de abril de 2013 9:00
RE: Current URL in velocity variable Jacques Traore 5 de abril de 2013 5:56
RE: Current URL in velocity variable Henry K 4 de abril de 2013 11:41
RE: Current URL in velocity variable Jacques Traore 5 de abril de 2013 7:04
RE: Current URL in velocity variable Praneeth T 21 de abril de 2015 23:04
RE: Current URL in velocity variable Vishal Kumar 6 de mayo de 2015 23:18
RE: Current URL in velocity variable Jignesh Vachhani 4 de agosto de 2012 22:14
RE: Current URL in velocity variable Aryan sds 18 de junio de 2013 23:13
RE: Current URL in velocity variable chirag @ India 18 de junio de 2013 23:25
RE: Current URL in velocity variable Aryan sds 19 de junio de 2013 0:49
RE: Current URL in velocity variable chirag @ India 19 de junio de 2013 2:04
RE: Current URL in velocity variable Aryan sds 19 de junio de 2013 5:03
RE: Current URL in velocity variable chirag @ India 19 de junio de 2013 22:02
RE: Current URL in velocity variable Aryan sds 20 de junio de 2013 0:57
RE: Current URL in velocity variable Aryan sds 26 de junio de 2013 23:46
RE: Current URL in velocity variable Jitender Soodan 15 de julio de 2013 18:46
Ishan Sahore
Current URL in velocity variable
2 de agosto de 2012 22:14
Respuesta

Ishan Sahore

Ranking: Junior Member

Mensajes: 56

Fecha de incorporación: 25 de abril de 2012

Mensajes recientes

Hi all,

I want to use the URL of current page in a velocity template variable.
Can anyone tell me the syntax as to which method to call to retrieve the URL?
Jignesh Vachhani
RE: Current URL in velocity variable
2 de agosto de 2012 22:58
Respuesta

Jignesh Vachhani

Ranking: Liferay Master

Mensajes: 785

Fecha de incorporación: 10 de marzo de 2008

Mensajes recientes

You can use $theme_display.getURLCurrent() in your theme velocity template
Hope this will work !!!
Ishan Sahore
RE: Current URL in velocity variable
3 de agosto de 2012 0:00
Respuesta

Ishan Sahore

Ranking: Junior Member

Mensajes: 56

Fecha de incorporación: 25 de abril de 2012

Mensajes recientes

Jignesh Vachhani:
You can use $theme_display.getURLCurrent() in your theme velocity template
Hope this will work !!!



Thanks Jignesh,

It shows the relative URL. Isn't there a way to get the absolute URL?

Thanks,
Ishan
Bart Simpson
RE: Current URL in velocity variable
3 de agosto de 2012 0:05
Respuesta

Bart Simpson

Ranking: Liferay Master

Mensajes: 524

Fecha de incorporación: 29 de agosto de 2011

Mensajes recientes

You can combine it with
1 $theme_display.getPortalURL()
Jignesh Vachhani
RE: Current URL in velocity variable
4 de agosto de 2012 22:14
Respuesta

Jignesh Vachhani

Ranking: Liferay Master

Mensajes: 785

Fecha de incorporación: 10 de marzo de 2008

Mensajes recientes

You can append it using:
$theme_display.getURLPortal() $theme_display.getURLCurrent()

HTH,
Liferay Solutions
Ishan Sahore
RE: Current URL in velocity variable
3 de agosto de 2012 0:32
Respuesta

Ishan Sahore

Ranking: Junior Member

Mensajes: 56

Fecha de incorporación: 25 de abril de 2012

Mensajes recientes

Thanks Jignesh and Paul,

So the absolute URL can be retrieved by the following:

$theme_display.getPortalURL().$theme_display.getURLCurrent()



Thanks,
Ishan
Jacques Traore
RE: Current URL in velocity variable
4 de abril de 2013 7:34
Respuesta

Jacques Traore

Ranking: Junior Member

Mensajes: 47

Fecha de incorporación: 21 de enero de 2013

Mensajes recientes

Hi all,
Why can't I access $theme_display?
Writting
1$theme_display.getPortalURL()
in the "Launch editor" just prints "$theme_display.getPortalURL()" and not the content of the url.

I am using LR 6.1.1 with a customs structure and template.

Thanks
James Falkner
RE: Current URL in velocity variable
4 de abril de 2013 9:00
Respuesta

James Falkner

Community Moderator

Ranking: Liferay Legend

Mensajes: 1406

Fecha de incorporación: 17 de septiembre de 2010

Mensajes recientes

Jacques Traore:
Hi all,
Why can't I access $theme_display?
Writting
1$theme_display.getPortalURL()
in the "Launch editor" just prints "$theme_display.getPortalURL()" and not the content of the url.

I am using LR 6.1.1 with a customs structure and template.

Thanks


There is a different set of variables available in Velocity, depending on whether you are writing a Theme template, or a Web Content template. This is detailed here.

For Web Content, there is no $theme_display. Instead, you get a $request Map that contains many of the items normally found in a ThemeDisplay object.

I often find myself calling services in Liferay that expect something that looks like a Theme Display, so I end creating a fake one, and populating it with stuff from the $request map (in particular, notice the $portalURL that I construct):

 1
 2
 3#set ($themeDisplay = $portal.getClass().forName("com.liferay.portal.theme.ThemeDisplay").newInstance())
 4#set ($portalURL = $httpUtil.getProtocol($request.attributes.CURRENT_URL) + "://" + $getterUtil.getString($request.theme-display.portal-url))
 5
 6#set ($V = $themeDisplay.setPathImage($getterUtil.getString($request.theme-display.path-image)))
 7#set ($V = $themeDisplay.setPathMain($getterUtil.getString($request.theme-display.path-main)))
 8#set ($V = $themeDisplay.setPermissionChecker($permissionThreadLocal.getPermissionChecker()))
 9#set ($V = $themeDisplay.setPortalURL($portalURL))
10#set ($V = $themeDisplay.setScopeGroupId($scopeGroupId))
11#set ($V = $themeDisplay.setTimeZone($request.theme-display.time-zone))
12
13## stuff...
14
15#set ($userPic = $user.getPortraitURL($themeDisplay))
Jacques Traore
RE: Current URL in velocity variable
5 de abril de 2013 5:56
Respuesta

Jacques Traore

Ranking: Junior Member

Mensajes: 47

Fecha de incorporación: 21 de enero de 2013

Mensajes recientes

Thank you James for replying,
Searching deeply, I've found that I have some troubles with the $request variable. I'm not sure to well understand how it works.
This is a use case:
1- I created an Asset Publisher to display custom web contents with custom structure and template.
2- In the template editor I wrote:
 1
 2## Some set ...
 3#set ($redirect = $request.get("parameters").get("redirect"))
 4## Some set ...
 5
 6#set ($axesMap = {"axis1" : "Axis 1" , "axis2" : "Axis 2" , "axis3" : "Axis 3" , })
 7
 8...
 9Request = $request
10  #if($redirect)
11    <img class="ProfileImage" src="${Picture.getData()}" border="0" align="right" alt="" />
12    <p class="SubTitle">$Axes.getName()</p>   
13    #foreach( $axis in $Axes.getOptions())
14      <a class="Axis"  href="/web/my-company/$axis">
15        $axesMap.get($axis)
16      </a>
17      <br/>
18    #end
19
20 ## Print some stuffs ....
21
22  #else
23    #foreach( $axis in $Axes.getOptions())
24      <a class="Axis"  href="/web/my-company/$axis">
25        $axesMap.get($axis)
26      </a>
27      <br/>
28    #end
29  #end

The first time the Asset Publisher is displayed, the $request is null (it shows {}) and after clicking on the web content title, the $request as a value.
At this point, it doesn't "very" matter. But when I edit a content and click on "Preview" button, the $request is {}.
However, I need its value, particularly the "cmd" parameter in preview and view (from history) modes to show the full content.
Therefore it only shows the abstract value of the content.
Same case when I try to visualize a published content from control panel (using Kaleo workflow plugin) before approve/reject it.

Otherwise, if you know another way to achieve this, may be creating many templates and doing association between view mode and template or whatever please let me know.

Thanks again
Henry K
RE: Current URL in velocity variable
4 de abril de 2013 11:41
Respuesta

Henry K

Ranking: Junior Member

Mensajes: 40

Fecha de incorporación: 27 de enero de 2010

Mensajes recientes

You can get the actual request and themeDisplay object in web content via:

#set ($serviceContext = $portal.getClass().forName("com.liferay.portal.service.ServiceContextThreadLocal").getServiceContext())
#set ($httpServletRequest = $serviceContext.getRequest())
#set ($objThemeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))

See the 3rd to last comment at http://www.liferay.com/web/raymond.auge/blog/-/blogs/custom-velocity-tools-and-liferay-6-0 . This works in 6.1.1 CE . Thanks Ray!
Jacques Traore
RE: Current URL in velocity variable
5 de abril de 2013 7:04
Respuesta

Jacques Traore

Ranking: Junior Member

Mensajes: 47

Fecha de incorporación: 21 de enero de 2013

Mensajes recientes

Thanks a lot Henry K,
It works very fine !!!
Aryan sds
RE: Current URL in velocity variable
18 de junio de 2013 23:13
Respuesta

Aryan sds

Ranking: Junior Member

Mensajes: 57

Fecha de incorporación: 24 de abril de 2012

Mensajes recientes

Hi Jignesh ,

Using your way I am getting exactly my current page url, Now how can I check whether this url contents some parameters are present or not

like my url may contains parameters like &customerName="sds"

So how can I check this whether it contents this parameter with given value or not?

Thanks,
Pravin
chirag @ India
RE: Current URL in velocity variable
18 de junio de 2013 23:25
Respuesta

chirag @ India

Ranking: Regular Member

Mensajes: 129

Fecha de incorporación: 20 de diciembre de 2011

Mensajes recientes

Hi Aryan sds ,

You can get parameter value using below line in velocity template and after You can used if condition for further operation.

I gets email value here..
1#set($isemail = $request.get("parameters").get("email"))


HTH
Chirag@India
Aryan sds
RE: Current URL in velocity variable
19 de junio de 2013 0:49
Respuesta

Aryan sds

Ranking: Junior Member

Mensajes: 57

Fecha de incorporación: 24 de abril de 2012

Mensajes recientes

Hi Chirag, thanks for quick reply.
I have tried to use your way to get value for parameter 'customerName' in this way and also printed '$customer' in this way
1#set($customer= $request.get("parameters").get("customerName"))
2
3$customer

But I am not getting anything when I am trying to see value $customer. According to my understanding if paramter 'customerName' value is null or empty it will return blank so when I am trying to print '$customer' , my result should be either blank or null but I am getting result as '$customer' string itself.


Am I written above code in correct way?

Thanks,
Aryan sds
chirag @ India
RE: Current URL in velocity variable
19 de junio de 2013 2:04
Respuesta

chirag @ India

Ranking: Regular Member

Mensajes: 129

Fecha de incorporación: 20 de diciembre de 2011

Mensajes recientes

Aryan sds:
Hi Chirag, thanks for quick reply.
I have tried to use your way to get value for parameter 'customerName' in this way and also printed '$customer' in this way
1#set($customer= $request.get("parameters").get("customerName"))
2
3$customer

But I am not getting anything when I am trying to see value $customer. According to my understanding if paramter 'customerName' value is null or empty it will return blank so when I am trying to print '$customer' , my result should be either blank or null but I am getting result as '$customer' string itself.


Am I written above code in correct way?

Thanks,
Aryan sds

hi Aryan ,

You are absolutely right .if parameter value null then its print your variable as it is.

HTH
Chirag@India
Aryan sds
RE: Current URL in velocity variable
19 de junio de 2013 5:03
Respuesta

Aryan sds

Ranking: Junior Member

Mensajes: 57

Fecha de incorporación: 24 de abril de 2012

Mensajes recientes

Hi Chirag , I am trying in this way.

1#set ($url = $themeDisplay.getURLCurrent())
2
3#if($url.contains("&customerName"))
4
5#set($customer= $url.get("parameters").get("customerName"))
6
7$customer
8#end


But I am not getting $customer value though my url contains value for customerName

My url is like :
1group/people/mainHome&customerName=Aryan


Why I am not getting value for $customer as Aryan ?
chirag @ India
RE: Current URL in velocity variable
19 de junio de 2013 22:02
Respuesta

chirag @ India

Ranking: Regular Member

Mensajes: 129

Fecha de incorporación: 20 de diciembre de 2011

Mensajes recientes

Aryan sds:
Hi Chirag , I am trying in this way.

1#set ($url = $themeDisplay.getURLCurrent())
2
3#if($url.contains("&customerName"))
4
5#set($customer= $url.get("parameters").get("customerName"))
6
7$customer
8#end


But I am not getting $customer value though my url contains value for customerName

My url is like :
1group/people/mainHome&customerName=Aryan


Why I am not getting value for $customer as Aryan ?


hi aryan ,

you have to use $request instead of $url because when form submits then $request object is used to get parameter.
#set($customer= $request.get("parameters").get("customerName"))

one another way

If you get $url & its print whole url then you can split that url & get particular value
#set ($current_url = $request.get("attributes").CURRENT_COMPLETE_URL) //to get complate url in velocity

#set($customervalue=$url.split("customerName=").get(1))

$customervalue


HTH
Chirag@India
Aryan sds
RE: Current URL in velocity variable
20 de junio de 2013 0:57
Respuesta

Aryan sds

Ranking: Junior Member

Mensajes: 57

Fecha de incorporación: 24 de abril de 2012

Mensajes recientes

Hi chirag,

Its working !!emoticon
Thanks for great help....

Aryan sds
Aryan sds
RE: Current URL in velocity variable
26 de junio de 2013 23:46
Respuesta

Aryan sds

Ranking: Junior Member

Mensajes: 57

Fecha de incorporación: 24 de abril de 2012

Mensajes recientes

Sometimes my url becomes like
1  http://localhost:8080/web/guest/sign-in?p_p_id=45&p_p_lifecycle=0&_58_redirect=‌​%2Fgroup%2Femployee%2FmainForm%3FempName%3DABC


So I have decoded this url by this way.

1#set($absoluteUrl= $theme_display.getURLCurrent())
2#set ($test=$httpUtil.decodeURL($absoluteUrl))


So my url becomes

$test=/web/guest/sign-in?p_p_id=58&p_p_lifecycle=0&_58_redirect=/group/employee/mainForm?empName=ABC

Now I want to check again value of empName , So I am trying in this way.

1[code]#set($empName= $request.getParameter("empName"))

$empName

but I am not getting value of empName .

How can I get value of empName now?
Jitender Soodan
RE: Current URL in velocity variable
15 de julio de 2013 18:46
Respuesta

Jitender Soodan

Ranking: New Member

Mensajes: 5

Fecha de incorporación: 16 de junio de 2011

Mensajes recientes

Hi Aryan,

After scratching my head for a while I found that if you set a variable in velocity templates in Liferay, the variables are not available for use until you restart the Liferay Service.

Try that and see if that helps.
Praneeth T
RE: Current URL in velocity variable
21 de abril de 2015 23:04
Respuesta

Praneeth T

Ranking: New Member

Mensajes: 1

Fecha de incorporación: 6 de marzo de 2014

Mensajes recientes

absolute URL can also retrieved as follows:

$portalUtil.getCurrentCompleteURL($request)
Vishal Kumar
RE: Current URL in velocity variable
6 de mayo de 2015 23:18
Respuesta

Vishal Kumar

Ranking: Regular Member

Mensajes: 198

Fecha de incorporación: 11 de diciembre de 2012

Mensajes recientes

Praneeth T:
$portalUtil.getCurrentCompleteURL($request)



Great!!!