Foros de discusión

Friendly URL In Velocity Template

thumbnail
Josh Asbury, modificado hace 15 años.

Friendly URL In Velocity Template

Expert Mensajes: 498 Fecha de incorporación: 8/09/06 Mensajes recientes
I have created a template which uses the link to page feature in the structure -- linking an image to a page.
#if ($image-link.getData() != "")
					<a href="$image-link.getUrl()" #end < code></a>
<a href="$image-link.getUrl()" #end < code><br><br>The getUrl() works fine, but I am wondering if there is a way to get the Friendly URL in a template. Any ideas?</a>
thumbnail
Amos Fong, modificado hace 15 años.

RE: Friendly URL In Velocity Template

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Hey Josh,

I can't think of an easy way to do it...

#set ($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalServiceUtil"))

#set ($layoutId = $getterUtil.getLong($image-link.getData()))

#set ($themeDisplay = $request.get('theme-display'))
#set ($currentPlid = $getterUtil.getLong($themeDisplay.get('plid')))
#set ($currentLayout = $layoutLocalService.getLayout($currentPlid))

#set ($layout = $layoutLocalService.getLayout($getterUtil.getLong($groupId), $currentLayout.isPrivateLayout(), $layoutId))

@friendly_url_current@/@group_friendly_url@$layout.getFriendlyURL()
Antonio Marcos Bernal, modificado hace 14 años.

RE: Friendly URL In Velocity Template

New Member Mensajes: 6 Fecha de incorporación: 19/05/09 Mensajes recientes
hi !!

i have a template with a page link and i used <a href="$ilink.getUrl()"/> to go to this page , but now i need to show the friendly_url instead of web/guest/10209/8 for example..
With your code i can show the friendly url of the actual page but no the link page url that show the mozilla when i used the href
Can anybody help me?
Thank you very much
Antonio Marcos Bernal, modificado hace 14 años.

RE: Friendly URL In Velocity Template

New Member Mensajes: 6 Fecha de incorporación: 19/05/09 Mensajes recientes
Excuse me but i see my problem is only that $currentLayout = $layoutLocalService.getLayout($currentPlid)) don´t return anything,,,anybody test this code??
thumbnail
Amos Fong, modificado hace 14 años.

RE: Friendly URL In Velocity Template

Liferay Legend Mensajes: 2047 Fecha de incorporación: 7/10/08 Mensajes recientes
Did you enable the servicelocator in your templates?

in portal.properties:

journal.template.velocity.restricted.variables=

http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Access+to+Liferay+services+in+Velocity
Robert Kornmesser, modificado hace 12 años.

RE: Friendly URL In Velocity Template

Junior Member Mensajes: 39 Fecha de incorporación: 3/11/11 Mensajes recientes
Its NOT
#set ($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalServiceUtil"))

BUT
#set ($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))

Finding services works by looking up the bean name, not the util. Otherwise you get a "NoSuchBeanDefinitionException: No bean named 'com.liferay.portal.service.LayoutLocalServiceUtil' is defined"
thumbnail
Dave Weitzel, modificado hace 11 años.

RE: Friendly URL In Velocity Template

Regular Member Mensajes: 208 Fecha de incorporación: 18/11/09 Mensajes recientes
I have found this thread and though it solved my problem as well but it doesn't.

I have a custom navigation template that is part of the theme (user has added own links etc) .
I want to detect if the link is actually to the current "site" so I can give it a different class.

I see you are using :

@friendly_url_current@/@group_friendly_url@

as a way of getting the current site's url and when I put this in the journal temp[lpate as straight text it returns what I want:
/web/mysite

BUT if I create a velocity variable
#set ( $fURL = '@friendly_url_current@/@group_friendly_url@')
it will still print out correctly but when I do something like link.getData().startsWith($fURL) I never get a hit as fURL contains the string @friendly_url_current@/@group_friendly_url@ it has length 42 characters.

I have never seen these sort of variables: @friendly_url_current@/@group_friendly_url@ ?
Where do they come from?
How can I pre-process their results to use in velocity functions?

I am expanding the journal content directly in the theme templates so do not have themeDIsplay and other normal velocity functions to work with

Thanks
thumbnail
Corné Aussems, modificado hace 10 años.

RE: Friendly URL In Velocity Template

Liferay Legend Mensajes: 1313 Fecha de incorporación: 3/10/06 Mensajes recientes
I was forwarded to this post, but its easier nowadays but for future references


dynamic-element name="linkFoo" type="link_to_layout" index-type="" /&gt;
$linkFoo.getFriendlyUrl()


updated: getFriendlyUrl >> getFriendlyURL
thumbnail
Corné Aussems, modificado hace 10 años.

RE: Friendly URL In Velocity Template

Liferay Legend Mensajes: 1313 Fecha de incorporación: 3/10/06 Mensajes recientes
Mind the CAP, Mind the CAP, Mind the CAP,
Oops now i made the same assumption,

it should be

$linkFoo.getFriendlyUrl()


NOT
$linkFoo.getFriendlyURL()