Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: How to get render url in Velocity template in 7.1
I have a simple velocity template that was working just fine in 6.2. Now I am going through the upgrade process to 7.1, and the template stopped working because it seems that the $request is not longer available.
Does anybody know if that's the case or I am just missing something? And is it possible to render url in some different way? And if so, how?
The code is below:
Thank you very much.
Alla
Does anybody know if that's the case or I am just missing something? And is it possible to render url in some different way? And if so, how?
The code is below:
##Get portlet URL
#set ($url = $request.get('render-url'))
#set ($namespace = $request.get('portlet-namespace'))
#set ($paramName = $request.get('parameters').get('paramName'))
#set ($themeDisplay = $httpServletRequest.getAttribute("THEME_DISPLAY"))
#if ($paramName)
Hello ${paramName}!
<form class="form-search" action="$url" method="post" name="${namespace}frm">
<div class="input-appended">
## Please enter your search keyword:
<input type="text" class="field" size="20" name="${namespace}paramName" value="$paramName">
<!--button type="submit" class="btn">Search</button-->
<input type="image" src="/BSCFixed-theme/images/common/search.png" alt="Submit">
<a class="search-links" href="$url">Back</a>
<a class="search-links" href="/group/dppos/directory">Advanced Search</a>
</div>
#set($companyId = $themeDisplay.getCompanyId())
#set ($userService = $serviceLocator.findService("com.liferay.portal.service.UserLocalService"))
#set ($phoneService = $serviceLocator.findService("com.liferay.portal.service.PhoneLocalService"))
##search user by screen name
##get all users in current organization
#set ($organizationId = $getterUtil.getLong($groupId) - 1)
#set ($userList = $userService.getOrganizationUsers($organizationId))
#set ($count = 1 )
#foreach ($user in $userList)
#set ($idxfirst = $user.getFirstName().toUpperCase().indexOf($paramName.toUpperCase()))
#set ($idxlast = $user.getLastName().toUpperCase().indexOf($paramName.toUpperCase()))
#if ($idxlast >-1 || $idxfirst >-1)
#if ($count == 1)
<table class="lfr-table-display">
<tbody><tr>
<th>Name</th>
<th>Email Address</th>
<th>Phone Number</th>
</tr>
#set ($count = 2 )
#end
<tr>
<!--td>$user.getScreenName()</td-->
<td class="dppusname">$user.getFirstName() $user.getLastName()</td>
<!--td><a href="mailto:$user.getEmailAddress()?Subject=Hello%20again" target="_top">
$user.getEmailAddress</a></td-->
<td class="dppusemail"><a href="mailto:$user.getEmailAddress()" target="_top">
$user.getEmailAddress()</a></td>
#set ($phoneList = $phoneService.getPhones($companyId, 'com.liferay.portal.model.Contact',$user.getContactId()))
<td class="dppusphone">
#foreach ($phone in $phoneList)
#if ($phone.primary)
$phone.number ext. $phone.extension <br>
#end
</td>
#end
</tr>
#end
#end
#if ($count == 2)
</tbody></table>
</form>
#else
No Users Found
#end
#else
<form class="form-search" action="$url" method="post" name="${namespace}frm">
<div class="input-appended">
## Please enter your search keyword:
<input type="text" class="field" size="20" name="${namespace}paramName">
<!--button type="submit" class="btn">Search</button-->
<input type="image" src="/BSCFixed-theme/images/common/search.png" alt="Submit">
<a class="search-links" href="/group/dppos/directory">Advanced Search</a>
</div>
</form>
#end
Thank you very much.
Alla
Hi Alla,
Please take into account the following article:
https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-1/updating-theme-templates
Which kind of template is your template? Theme, ADT or WCM template?
Thanks.
Please take into account the following article:
https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-1/updating-theme-templates
Which kind of template is your template? Theme, ADT or WCM template?
Thanks.
Hi Alberto,
This is a simple web content template.
I know that Velocity is deprecated. But the question still remains: is request available in Web Content template? And if not, how can I get render url and other request components?
Thank you very much for your help.
Alla
This is a simple web content template.
I know that Velocity is deprecated. But the question still remains: is request available in Web Content template? And if not, how can I get render url and other request components?
Thank you very much for your help.
Alla
How can I get render url or request in FreeMaker WCM Template ?
Hi Alla,
This question has been asked several times before in the forums (I know this because I have answered it before myself) -- but here is some sample code, again, on one option for doing it.
This question has been asked several times before in the forums (I know this because I have answered it before myself) -- but here is some sample code, again, on one option for doing it.
<#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext() />
<#assign request = serviceContext.getRequest() />
<#assign portletURLFactoryUtil = staticUtil["com.liferay.portal.kernel.portlet.PortletURLFactoryUtil"]/>
<#assign portletId = "com_ml_some_web.portlet_fake_FakePortlet" />
<#assign plid = layout.getPlid() />
<#assign phase = "RENDER_PHASE" />
<#assign portletRenderUrl = portletURLFactoryUtil.create(request, portletId, plid, phase)/>
<a href="${portletRenderUrl}" class="btn btn-primary">Render Portlet</a>
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™