RE: Error in Template Freemaker 7.4

Jamie Sammons, modified 2 Years ago. New Member Posts: 13 Join Date: 11/21/23 Recent Posts

Hello everyone,
in Liferay 7.1 I used this piece of code in an FTL Template to get users to print and it worked.

<#assign UserLocalService = serviceLocator.findService("com.liferay.portal.kernel.service.UserLocalService")>
<#assign users = UserLocalService.getUsers(0,10)>
<br/>
<#list users as user>
            ${user}
</#list>


Now I tried in Liferay DXP 7.4 and it doesn't work anymore, telling me:
The following has evaluated to null or missing:
==> serviceLocator [in template "4573561063168409277#20119#32927" at line 1, column 29]

How has it changed in DXP and what do I replace it with?

thanks,

F

 

thumbnail
Mohammed Yasin, modified 2 Years ago. Liferay Master Posts: 593 Join Date: 8/8/14 Recent Posts

Hi,

You can try removing serviceLocator from restricted varibles list.

System Setting -> Template Engines -> here u need remove "serviceLocator" from restricted variable list.

Priyank Gajera, modified 2 Years ago. New Member Posts: 2 Join Date: 11/23/22 Recent Posts

Hi Francesco,

If it's possible try to avoid usage of serviceLocator but if it's really needed then on top removing "serviceLocator" from restricted variable list you also need to add "com.liferay.portal.kernel.service.UserLocalService" in the