Legacy Knowledge Base
Published Jul. 2, 2025

Handling Freemarker Template Errors in the UI

Written By

Katlyn Lee

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

While we make every effort to ensure this Knowledge Base is accurate, itmay not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with anyfeedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

Before using any information from this article, independently verify itssuitability for your situation and project.

Issue

  • Liferay renders Freemarker Template errors in the UI, particularly when a Web Content template references a non-existent value from a Web Content structure. This can potentially cause confusion or negative user experience for a non-admin user visiting the site.

         Freemarker_Error.png

Environment

  • Liferay DXP 7.0 - 7.3

Resolution

When building the Freemarker template, implement attempt and recover blocks, as described in https://freemarker.apache.org/docs/ref_directive_attempt.html. This would allow user-friendly errors to be rendered in the UI if the template variables do not exist. For example:

Test Content:
<#attempt>
  Company Name: ${companyName}
<#recover>
  Unable to retrieve Company Name.
</#attempt>

If the companyName variable doesn't exist (or any other error occurs at that place), then the output would be:

Test Content:
Unable to retrieve Company Name.

If the companyName variable exists and it's value is Liferay, then the output would be:

Test Content:
Liferay

Additional Information

A Feature Request ticket has been created for Freemarker Templates to be displayed only the browser console or Liferay logs and for a more user-friendly error message to instead be displayed in the UI. Please see LPS-119835 for more information.

Did this article resolve your issue ?

Legacy Knowledge Base