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.
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.