<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Can't fetch documents with freemarker on templates</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=94828122" />
  <subtitle>Can't fetch documents with freemarker on templates</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=94828122</id>
  <updated>2026-04-06T17:48:20Z</updated>
  <dc:date>2026-04-06T17:48:20Z</dc:date>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119641290" />
    <author>
      <name>chinmay abhyankar</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=119641290</id>
    <updated>2020-07-24T07:14:54Z</updated>
    <published>2020-07-24T07:14:54Z</published>
    <summary type="html">&amp;lt;#list attachmentURL.getData()?split(&amp;#34;/&amp;#34;) as x&amp;gt;    &amp;lt;#if x?counter ==3&amp;gt;&lt;br /&gt;        &amp;lt;#assign groupId = x?number&amp;gt;&lt;br /&gt;    &amp;lt;/#if&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;#if x?counter ==6&amp;gt;&lt;br /&gt;        &amp;lt;#assign uuId = x?keep_before(&amp;#34;?&amp;#34;)&amp;gt;&lt;br /&gt;    &amp;lt;/#if&amp;gt;&lt;br /&gt;&amp;lt;/#list&amp;gt;&amp;lt;#assign dlFileEntry = serviceLocator.findService(&amp;#34;com.liferay.document.library.kernel.service.DLFileEntryLocalService&amp;#34;)&amp;gt; &lt;br /&gt;&amp;lt;#if (uuId??) &amp;amp;&amp;amp; (groupId??)&amp;gt;&lt;br /&gt;&amp;lt;#assign file = dlFileEntry.getFileEntryByUuidAndGroupId(uuId,groupId) &amp;gt;    ${file.getSize()/1000000} &amp;lt;#--will return file size in MB--&amp;gt;&lt;br /&gt;&amp;lt;/#if&amp;gt;</summary>
    <dc:creator>chinmay abhyankar</dc:creator>
    <dc:date>2020-07-24T07:14:54Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118871223" />
    <author>
      <name>Lee Jordan</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=118871223</id>
    <updated>2020-04-06T21:48:08Z</updated>
    <published>2020-04-06T21:48:08Z</published>
    <summary type="html">If anyone at Liferay can offer the community guidance here, this is a real pain point for a lot of template developers.</summary>
    <dc:creator>Lee Jordan</dc:creator>
    <dc:date>2020-04-06T21:48:08Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=95023245" />
    <author>
      <name>Yannis Sinadinos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=95023245</id>
    <updated>2017-09-18T13:50:26Z</updated>
    <published>2017-09-18T13:50:26Z</published>
    <summary type="html">DLFileEntryLocalServiceUtil exists here: &lt;br /&gt;https://docs.liferay.com/portal/7.0/javadocs/portal-kernel/com/liferay/document/library/kernel/service/DLFileEntryLocalServiceUtil.html&lt;br /&gt;&lt;br /&gt;Strange behaviour of StaticUtils or we are missing something.</summary>
    <dc:creator>Yannis Sinadinos</dc:creator>
    <dc:date>2017-09-18T13:50:26Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94833047" />
    <author>
      <name>Massimo Bevilacqua</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94833047</id>
    <updated>2017-09-13T11:58:39Z</updated>
    <published>2017-09-13T11:58:39Z</published>
    <summary type="html">StaticUtil works,&lt;br /&gt;for example if I insert this code it works.&lt;br /&gt;&lt;blockquote&gt;&amp;lt;#assign serviceContextThreadLocal = staticUtil[&amp;#34;com.liferay.portal.kernel.service.ServiceContextThreadLocal&amp;#34;] /&amp;gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I have a  &amp;#34;class not found&amp;#34; error , it seems it is not able to found the class DLFileEntryLocalServiceUtil</summary>
    <dc:creator>Massimo Bevilacqua</dc:creator>
    <dc:date>2017-09-13T11:58:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94832843" />
    <author>
      <name>Yannis Sinadinos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94832843</id>
    <updated>2017-09-13T11:39:36Z</updated>
    <published>2017-09-13T11:39:36Z</published>
    <summary type="html">It worked with serviceLocator.  Still can&amp;#39;t understand why staticUtil is not working.&lt;br /&gt;&lt;br /&gt;Thank you Massimo for the quick reply.</summary>
    <dc:creator>Yannis Sinadinos</dc:creator>
    <dc:date>2017-09-13T11:39:36Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94832371" />
    <author>
      <name>Massimo Bevilacqua</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94832371</id>
    <updated>2017-09-13T10:56:07Z</updated>
    <published>2017-09-13T10:56:07Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Instead of staticUtil try serviceLocator&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign dlFileEntryService = serviceLocator.findService('com.liferay.document.library.kernel.service.DLFileEntryService') /&amp;amp;gt; 
&amp;amp;lt;#assign file = dlFileEntryService.getFileEntryByUuidAndGroupId(uuId,groupId)  &amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;I never used a config file inside bundle/osgi/config, I added these lines in my portal-ext.properties&lt;br&gt;&lt;br&gt;&lt;blockquote&gt;freemarker.engine.restricted.classes=&lt;br&gt;freemarker.engine.restricted.packages=&lt;br&gt;freemarker.engine.restricted.variables=&lt;/blockquote&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Massimo Bevilacqua</dc:creator>
    <dc:date>2017-09-13T10:56:07Z</dc:date>
  </entry>
  <entry>
    <title>RE: Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94828214" />
    <author>
      <name>Yannis Sinadinos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94828214</id>
    <updated>2017-09-13T10:19:10Z</updated>
    <published>2017-09-13T10:19:10Z</published>
    <summary type="html">I also created the cfg file in bundle/osgi/config as mentioned &lt;a href="https://web.liferay.com/en/community/forums/-/message_boards/message/94827735"&gt;here &lt;/a&gt; but still no luck... &lt;br /&gt;&lt;br /&gt;Even when setting &amp;#34;restrictedVariables = &amp;#34; I still get the same error or my portal faces Internal server error 500 and I have to recove it by deleting the related entries in configuration_ table. Check this &lt;a href="https://web.liferay.com/community/forums/-/message_boards/message/83643369"&gt;issue &lt;/a&gt;for more details.&lt;br /&gt;&lt;br /&gt;I am using Liferay 7.0 GA4</summary>
    <dc:creator>Yannis Sinadinos</dc:creator>
    <dc:date>2017-09-13T10:19:10Z</dc:date>
  </entry>
  <entry>
    <title>Can't fetch documents with freemarker on templates</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94828121" />
    <author>
      <name>Yannis Sinadinos</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=94828121</id>
    <updated>2017-09-13T09:59:18Z</updated>
    <published>2017-09-13T09:59:18Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hi, &lt;br&gt;I created a structure which contains documents and also created the related template. &lt;br&gt;In the template I added freemarker code to fetch the documents these but is not working.&lt;br&gt;&lt;br&gt;My code is &lt;br&gt;&lt;pre&gt;&lt;code&gt;    &amp;amp;lt;#assign fileEntry = staticUtil["com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil"]&amp;amp;gt;
    &amp;amp;lt;#assign file = fileEntry.getFileEntryByUuidAndGroupId(uuId,groupId)&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;and the error&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;09:16:07,089 ERROR [http-nio-8080-exec-9][runtime:60] Error executing FreeMarker template
FreeMarker template 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]
----

Java stack trace (for programmers):
----
freemarker.template.TemplateModelException: [... Exception message was already printed; see it above ...]
        at freemarker.ext.beans.ClassBasedModelFactory.get(ClassBasedModelFactory.java:52)
        at freemarker.core.DynamicKeyName.dealWithStringKey(DynamicKeyName.java:145)
        at freemarker.core.DynamicKeyName._eval(DynamicKeyName.java:73)
        at freemarker.core.Expression.eval(Expression.java:78)
        at freemarker.core.Assignment.accept(Assignment.java:131)
        at freemarker.core.Environment.visit(Environment.java:324)
        at freemarker.core.MixedContent.accept(MixedContent.java:54)....&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;In order to use statitUtil I went to Control Panel -&amp;gt; Configuration -&amp;gt; System Settings -&amp;gt; Foundation -&amp;gt; FreeMarker Engine -&amp;gt; Restricted Variables.&lt;br&gt;and i deleted staticUtil and all the restricted Variables and classes. But no luck... Still getting this error...&lt;br&gt;&lt;br&gt;Any ideas?&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Yannis Sinadinos</dc:creator>
    <dc:date>2017-09-13T09:59:18Z</dc:date>
  </entry>
</feed>
