Message Boards
Need Help with Freemarker WCM Templates
Need Help with Freemarker WCM Templates
Regular Member Posts: 223 Join Date: 9/30/13 Recent PostsFor instance when I use this code:
<#assign journalArticleResourceLocalServiceUtil = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") />
I get this:
Expression serviceLocator is undefined on line 18, column 51 in 20155#20195#23618.
When I try:
<#assign journalArticleResourceService = portal.getClass().forName("com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil").getMethod("getService", null).invoke(null, null)/>
I get :
Expression portal.getClass().forName is undefined on line 16, column 42 in 20155#20195#23618.
When I try:
<#assign journalArticleResourceLocalServiceUtil = staticUtil["com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil"]>
I get a message that staticUtil is undefined.
Everything I try with the Freemarker objects like "serviceLocator", "portal" or "staticUtil" won't work. What am I missing? Do I have to initialize or to include something?
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsPlease add the following property to portal-ext.properties:
freemarker.engine.restricted.variables=
I am not a 100% sure, but I think you can use staticUtil only in ADTs, you can't use it in a Journalarticle template.
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent PostsRE: Need Help with Freemarker WCM Templates
Regular Member Posts: 223 Join Date: 9/30/13 Recent PostsI' ve added this to my portal-ext.properties, and restarted the Server:
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=
But I still get the same Error when using this:
<#assign journalArticleResourceLocalServiceUtil = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") />
Expression serviceLocator is undefined on line 18, column 51 in 20155#20195#23618.
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsI just tried it, it works for me with Liferay 6.2, I have these in the portal-ext.properties. Not sure if one of them makes a difference (it actually shouldn't, but who knows).
freemarker.engine.restricted.classes=
freemarker.engine.restricted.packages=
freemarker.engine.restricted.variables=
velocity.engine.restricted.classes=
velocity.engine.restricted.packages=
velocity.engine.restricted.variables=
Just to be paranoid: Could you check that these fields are really set? Control Panel -> Configuration -> Server Administration -> Portal Properties.
RE: Need Help with Freemarker WCM Templates
Regular Member Posts: 223 Join Date: 9/30/13 Recent Posts<#assign JournalArticleLocalService = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService")>
...and there are a couple of new service variables available beneath the template editor area, so the properties seem to take effect.
Unfortunately I still have no Idea on how to use the service now. For example I tried
<#assign articleResourcePK = JournalArticleLocalService.getArticleResourcePrimKey(groupId, .vars['reserved-article-id'].data) />
<#assign categoryList=assetCategoryLocalServiceUtil.getCategories("com.liferay.portlet.journal.model.JournalArticle",articleResourcePK) >
...and get this Error:
Expression JournalArticleLocalService.getArticleResourcePrimKey is undefined on line 22, column 30 in 20155#20195#23618.
It doesn't matter which method of JournalArticleLocalService I use, the method is always "undefined".
So I'm still stuck and can't my list of categories for the article.
RE: Need Help with Freemarker WCM Templates
Regular Member Posts: 223 Join Date: 9/30/13 Recent Postshttps://web.liferay.com/de/community/forums/-/message_boards/message/41897445
RE: Need Help with Freemarker WCM Templates
New Member Posts: 2 Join Date: 1/14/16 Recent PostsLiferay Version?
I just tried it, it works for me with Liferay 6.2, I have these in the portal-ext.properties. Not sure if one of them makes a difference (it actually shouldn't, but who knows).
freemarker.engine.restricted.classes=
freemarker.engine.restricted.packages=
freemarker.engine.restricted.variables=
velocity.engine.restricted.classes=
velocity.engine.restricted.packages=
velocity.engine.restricted.variables=
Just to be paranoid: Could you check that these fields are really set? Control Panel -> Configuration -> Server Administration -> Portal Properties.
Hi Christoph Rabel, i use Liferay 7, i had add
freemarker.engine.restricted.classes=
freemarker.engine.restricted.packages=
freemarker.engine.restricted.variables=
in the portal-ext.properties but it is not work. This error:
The following has evaluated to null or missing:
==> serviceLocator [in template "20115#20159#21341" at line 1, column 34]
----
Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing<!--#if-->. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??
Can you help me?
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsControl Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables.
There you can remove serviceLocator from the list. You probably want to restart afterwards otherwise the setting won't work immediately.
Please BE CAREFUL: There's a bug, you need to enter something valid like "java.lang.String" into the allowedClasses field or otherwise Liferay 7 won't start up after saving that form! That field must not contain an empty string!
RE: Need Help with Freemarker WCM Templates
New Member Posts: 2 Join Date: 1/14/16 Recent PostsrestrictedVariables=
It worked. Do you think it correct way?
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsSad to see that there is no real solution provided to that problem.
You can either use the control-panel, remove the restriction and hope your portal will work after that (if not, be faced with hours of additional work, I guess) or create that freemarkerengine config file as mentioned above.
Sadly though, that config part doesn't work for me!
Is there a new or better solution to this?
Do I have to do something for my OSGI configs to work?
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsIn any case, both given solutions work. You can either configure this in the frontend (but in GA3 you have to be a bit careful) or using the module configuration by file.
Could you explain what you are doing?
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsThe issue is fixed in GA4.
In any case, both given solutions work. You can either configure this in the frontend (but in GA3 you have to be a bit careful) or using the module configuration by file.
Could you explain what you are doing?
Sure. I have created a workspace and added a theme in folder themes/ that I created using the Theme Generator.
I then created the file 'com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg' as mentioned above inside <portal_home>/osgi/configs with the following content: restrictedVariables=
Did I do something wrong?
EDIT: I am using liferay-dxp-digital-enterprise-tomcat-7.0-sp1-20161027112321352
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsDid you restart after making that configuration?
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsHmm, that should work.
Did you restart after making that configuration?
I guess that was the problem.
Now, when I start up though, I am faced with a new Exception:
14:24:35,880 INFO [Start Level: Equinox Container: e0d6a5d3-5662-0017-1f26-f84065a78e69][BundleStartStopLogger:35] STARTED com.liferay.util.taglib_2.5.1 [544]
06-Jul-2017 14:24:35.889 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class com.liferay.portal.spring.context.PortalContextLoaderListener
java.lang.RuntimeException: java.nio.file.FileSystemNotFoundException: D:\liferay-portal-dxp\osgi\marketplace\Liferay Collaboration.lpkg
at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized(PortalContextLoaderListener.java:256)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4812)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5255)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
Does this have to do with the configuration I made? Seems to have to do with marketplace although I did not modify it.
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsIt's in the Liferay Zip file, so it should be there.
Did you, per chance, apply a Liferay patch(provided you are using EE)? You absolutely need to delete the osgi/state folder after patching. It might also help you here. Stop the server, delete the folder, start it again. It will take some extra time. Deleting the state folder is perfectly fine, it contains only "temporary" files.
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsAnd yes, I patched my instance recently.
I deleted the folder (which seemed to help), started up and get an error:
freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:_==> serviceLocator.findService("com.liferay.portal.service.LayoutLocalService")
I looked into Config > Foundation > Freemarker and saw that nothing changed. Still, my config lies in <lr-portal>/osgi/configs and is somehow registered in the database aswell. If I look into *.configuration, I see a table 'com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration' with value 'felix.fileinstall.filename="file:/D:/liferay-portal-dxp/osgi/configs/com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg"
restrictedVariables=""
service.pid="com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration"'
Is there any mistake I made?
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsNext Error I'm getting is:
10:30:54,310 ERROR [http-nio-8080-exec-1][error_jsp:670] javax.servlet.ServletException: javax.servlet.jsp.JspException: com.liferay.portal.kernel.template.TemplateException: Unsupported template manager ftl
javax.servlet.ServletException: javax.servlet.jsp.JspException: com.liferay.portal.kernel.template.TemplateException: Unsupported template manager ftl
at org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:905)
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
at com.liferay.taglib.servlet.PageContextWrapper.handlePageException(PageContextWrapper.java:164)
at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:721)
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsNow you are most likely hitting this issue:
Please BE CAREFUL: There's a bug, you need to enter something valid like "java.lang.String" into the allowedClasses field or otherwise Liferay 7 won't start up after saving that form! That field must not contain an empty string!
Upgrading to Patch 12 or SP2+ should fix that.
Here's a hint how to fix it manually:
https://web.liferay.com/community/forums/-/message_boards/message/83643369
P.S.:
No idea why the cfg file doesn't work. Everything looks correct.
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsHere's the output of the patching tool:
D:\liferay-portal-dxp\patching-tool>patching-tool.bat info
Loading product and patch information...
Product information:
* installation type: binary
* build number: 7010
* service pack version:
- available SP version: 3
- installable SP version: 3
* patching-tool version: 2.0.6
* time: 2017-07-07 11:34Z
* plugins: no plugins detected
Currently installed patches: de-22-7010
Available patches: de-7-7010, de-22-7010
Detailed patch list:
[ -] de-7-7010 :: Currently not installed; Won't be installed: de-22 contains the fixes included in this one
[*I] de-22-7010 :: Installed; Will be installed. :: Built for LIFERAY
I also did what was mentioned in the article under the link you posted and discovered, that the config file 'com.liferay.portal.template.freemarker.configuration.FreeMarkerEngineConfiguration.cfg' in portal/osgi/configs was modified and now contains the following:
restrictedVariables = [Ljava.lang.String;@b6008b6
allowedClasses = [Ljava.lang.String;@426f3cdf
localizedLookup = false
macroLibrary = [Ljava.lang.String;@13aa8072
resourceModificationCheck = 60
restrictedClasses = [Ljava.lang.String;@46b9133a
templateExceptionHandler = rethrow
RE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent PostsI'd try to delete the cfg file (or maybe move it away). Maybe it works afterwards. If so, I would try to repeat the steps to remove the restricted variables again through the frontend.
And then I would open a ticket with Liferay. Creating the file should work and your server should start up without an issue.
RE: Need Help with Freemarker WCM Templates
New Member Posts: 8 Join Date: 8/13/13 Recent PostsrestrictedVariable=
, restarted and it finally worked! Thanks for your support, Christopher!
RE: Need Help with Freemarker WCM Templates
Junior Member Posts: 39 Join Date: 3/20/17 Recent PostsNo idea what the problem is.
I'd try to delete the cfg file (or maybe move it away). Maybe it works afterwards. If so, I would try to repeat the steps to remove the restricted variables again through the frontend.
And then I would open a ticket with Liferay. Creating the file should work and your server should start up without an issue.
Hi, is there a clear solution for this issue? I followed the same steps and didn't work for me...
The set "restrictedValiables = " to cfg file in ..bundle/osgi/config folder but it is not working.
I try to use staticUtil method
<#assign fileEntry = staticUtil["com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil"]>
<#assign file = fileEntry.getFileEntryByUuidAndGroupId(uuId,groupId)>
and i get the following error:
No error description was specified for this error; low-level message: java.lang.ClassNotFoundException: com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil cannot be found by com.liferay.portal.template.freemarker_2.0.24
----
FTL stack trace ("~" means nesting-related):
- Failed at: #assign fileEntry = staticUtil["com.l... [in template "20116#20152#45193" at line 26, column 5]
RE: Need Help with Freemarker WCM Templates
New Member Posts: 4 Join Date: 9/20/18 Recent PostsI am trying to display content of a journal from within a journal. I went to "Control Panel -> Configuration -> System Settings -> Template Engines -> FreeMarker Engine -> Restricted Variables" and pretty much removed all variables and classes. I only have java.lang.Class and java.lang.Thread in restricted classes and still get the error. my code :Â
<#assign journalArticleService =
serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")
/>Â
<#assign paragraphArticle =
journalArticleService.fetchLatestArticle(author_map.getLong("classPK"))
/>Â
<#if paragraphArticle??>
${journalArticleService.getArticleContent(paragraphArticle,
paragraphArticle.getDDMTemplateKey(), Â "",
languageUtil.getLanguageId(locale), themeDisplay)}</#if>Â
Â
What Am I Missing?
RE: Need Help with Freemarker WCM Templates
New Member Posts: 9 Join Date: 9/18/19 Recent PostsRE: Need Help with Freemarker WCM Templates
Expert Posts: 449 Join Date: 5/26/15 Recent Posts
In Liferay 7 the configuration was moved from portal.properties to the new configuration store.
Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables.
7.2 Update add another step in the navigation ...
Control Panel -> Configuration -> System Settings -> Platform -> Template Engines -> FreeMarker Engine -> Restricted Variables - Repeatable Fields
And I found this file
https://github.com/liferay/liferay-portal/blob/master/modules/apps/portal-template/portal-template-freemarker/src/main/java/com/liferay/portal/template/freemarker/configuration/FreeMarkerEngineConfiguration.java
With:
@Meta.AD(
deflt = "httpUtilUnsafe|objectUtil|serviceLocator|staticFieldGetter|staticUtil|utilLocator",
name = "restricted-variables", required = false
)
Attachments:
RE: Need Help with Freemarker WCM Templates
New Member Posts: 2 Join Date: 8/11/15 Recent PostsThis is friggin crazy.
RE: Need Help with Freemarker WCM Templates
Expert Posts: 449 Join Date: 5/26/15 Recent PostsI too have spent too much time trying to get a list of site pages from Liferay. I could swear but I won't. I looked at it before Christmas and have picked it back up and still no hope in sight for accessing these variables.
Caused by: freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:_==> serviceLocator.findService("com.liferay.portal.service.LayoutLocalServiceUtil") [in template "mercury-theme_SERVLET_CONTEXT_/templates/init_custom.ftl" at line 55, column 26]__
Miserable. I'm a front end developer and can't access template variables? Absolutely miserable experience and a waste of time tying to put on a band aid to something that should never have been removed in the first place. As a front end dev I don't have the knowledge to go fix your product for me to restore a feature that should never have been removed.
RE: Need Help with Freemarker WCM Templates
Expert Posts: 449 Join Date: 5/26/15 Recent PostsRE: Need Help with Freemarker WCM Templates
Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Postshttps://help.liferay.com/hc/en-us/articles/360018170931-Template-Context-Contributor
Please note that it only works "as expected" from 7.0.0 DXP SP7 and up:
https://issues.liferay.com/browse/LPS-76631