Foren

6.2 Freemarker serviceLocator variable

thumbnail
Ken Driscoll, geändert vor 10 Jahren.

6.2 Freemarker serviceLocator variable

Junior Member Beiträge: 57 Beitrittsdatum: 02.07.12 Neueste Beiträge
I recently upgraded to Liferay 6.2 GA1, and now all of my custom Asset Publisher Display Templates (using Freemarker) throw errors saying "Expression serviceLocator is undefined". I did some research, and already have the following in my portal-ext.properties file:
journal.template.velocity.restricted.variables=
journal.template.freemarker.restricted.variables=

This had worked in the past to give me access to the "serviceLocator" variable, but now I no longer have it. Did something change in 6.2 that is causing this issue?

Thanks in advance.
thumbnail
James Falkner, geändert vor 10 Jahren.

RE: 6.2 Freemarker serviceLocator variable

Liferay Legend Beiträge: 1399 Beitrittsdatum: 17.09.10 Neueste Beiträge
Ken Driscoll:
I recently upgraded to Liferay 6.2 GA1, and now all of my custom Asset Publisher Display Templates (using Freemarker) throw errors saying "Expression serviceLocator is undefined". I did some research, and already have the following in my portal-ext.properties file:
journal.template.velocity.restricted.variables=
journal.template.freemarker.restricted.variables=

This had worked in the past to give me access to the "serviceLocator" variable, but now I no longer have it. Did something change in 6.2 that is causing this issue?

Thanks in advance.


The names of the configuration settings have changed (again).

They are now more generic, since variables like serviceLocator can also be used from other contexts like DDL templates and ADTs.. so try
velocity.engine.restricted.classes=
velocity.engine.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=


This will allow you to do everything you could do in 6.1. Also note that the new variables *.restricted.classes are there for a very good reason, and by default prevent unrestricted JVM class access, and should not disabled without fully understanding and accepting the consequences (that a web content template can take down your system, wipe out your production DB, or worse).
thumbnail
Ken Driscoll, geändert vor 10 Jahren.

RE: 6.2 Freemarker serviceLocator variable

Junior Member Beiträge: 57 Beitrittsdatum: 02.07.12 Neueste Beiträge
Many thanks James!
thumbnail
Alberto Glez, geändert vor 9 Jahren.

RE: 6.2 Freemarker serviceLocator variable

New Member Beiträge: 3 Beitrittsdatum: 07.01.14 Neueste Beiträge
This really save my day!! Many thanks James!
thumbnail
Enrique Valdes Lacasa, geändert vor 9 Jahren.

RE: 6.2 Freemarker serviceLocator variable

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
Hello everyone, and thank you James for the clarification. I have a question though, maybe someone in here can help.

I am implementing an Application Display Template (ADT) for the Asset Publisher. I am trying to retrieve the URL of a file in the document library to display it as a link for the users. The thing is that it looks like I will need to use some service in the ADT, so using the $serviceLocator variable could be very useful. But I am seeing in the Documentation of Portal Properties - Liferay 6.2 that it looks like this property is set by default: velocity.engine.restricted.variables=serviceLocator.

So this made me think...maybe this is because the use of the $serviceLocator variable is not quite recommended. Reading the description of the property, it says something like: "...this variable will be restricted in: DDL templates, Journal templates and Portlet Display Templates."...so:

1) Are ADTs included as DDL Templates, Journal templates or Portlet Display Templates?
2) Should I use service locator?
3) If the use of service locator is not recommended...would anyone have a better suggestion to implement this functionality?

Thanks and Happy Hollidays!
Andreas Wittig, geändert vor 6 Jahren.

RE: 6.2 Freemarker serviceLocator variable

New Member Beiträge: 3 Beitrittsdatum: 01.06.17 Neueste Beiträge
At least I got some answer from lester.pi@liferay.com regarding https://issues.liferay.com/browse/LPS-58698 :
"If you decide to have "velocity.engine.restricted.variables" empty then any user with permission to update/create templates can become administrator"