RE: How to get render url in Velocity template in 7.1

Alla Sapozhnikova, modified 6 Years ago. Junior Member Posts: 82 Join Date: 3/2/12 Recent Posts
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:



##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">
&nbsp;&nbsp;
<a class="search-links" href="$url">Back</a>&nbsp;&nbsp;
<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 &gt;-1 || $idxfirst &gt;-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">
&nbsp;&nbsp;
    <a class="search-links" href="/group/dppos/directory">Advanced Search</a>
  </div>  
</form>

 
  #end


Thank you very much.
Alla
thumbnail
Alberto Chaparro, modified 6 Years ago. Liferay Master Posts: 560 Join Date: 4/25/11 Recent Posts
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.
Alla Sapozhnikova, modified 6 Years ago. Junior Member Posts: 82 Join Date: 3/2/12 Recent Posts
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
Alla Sapozhnikova, modified 6 Years ago. Junior Member Posts: 82 Join Date: 3/2/12 Recent Posts
How can I get render url or request in FreeMaker  WCM Template ?
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
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.
&lt;#assign serviceContext = staticUtil["com.liferay.portal.kernel.service.ServiceContextThreadLocal"].getServiceContext() /&gt;
&lt;#assign request = serviceContext.getRequest() /&gt;
&nbsp;
&nbsp;
&lt;#assign portletURLFactoryUtil = staticUtil["com.liferay.portal.kernel.portlet.PortletURLFactoryUtil"]/&gt;
&nbsp;
&nbsp;
&lt;#assign portletId = "com_ml_some_web.portlet_fake_FakePortlet" /&gt;
&lt;#assign plid = layout.getPlid() /&gt;
&lt;#assign phase = "RENDER_PHASE" /&gt;
&nbsp;
&lt;#assign portletRenderUrl = portletURLFactoryUtil.create(request, portletId, plid, phase)/&gt;
&nbsp;
&nbsp;
<a href="${portletRenderUrl}" class="btn btn-primary">Render Portlet</a>