Issue
- How variables to be used across the site, primarily for Fragments, to assign dynamic values that can be changed and propagated from a single place.
Environment
- Liferay DXP 7.4 U4+
- Liferay DXP Quarterly Release
Resolution
NOTE: The following resolution requires customization and should only be implemented at the discretion of your team. Liferay Support will not be able to assist with designing or implementing customizations.
- In Liferay DXP, it's common to have certain values such as company names, taglines, contact numbers, or any reusable text that are used repeatedly across multiple sites and pages via Liferay fragment, Web comtent and in custom module JSP.
- To address this challenge, Liferay provides a powerful feature called Language Override, which can be effectively used to define configurable variables and manage values consistently across your instance.
- To define and use a configurable variable using Liferay’s Language Override feature, follow the steps below:
-
Start your Liferay DXP server and Navigate to the Control Panel and go to Configuration > Language Override.
-
Click on the "Add" button to create a new language override.
-
In the form that appears:
-
Enter the Language Key, which will act as the configurable variable (e.g.,
custom.key). - Set the Translation value, which is the text you want to store in en-US field.
-
-
Copy the language key created and save the configuration.
-
Now language key can be used in various Liferay components to dynamically insert the stored value.
Here are some examples of how to reference the key in different types of Liferay components:
-
In Fragments:
[@liferay.language key="custom.key"/]
-
In Web Content Templates and Lifray Themes:
<@liferay.language key="custom.key"/>
-
In JSP Files:
<@liferay.language key="custom.key"/>
-
Once implemented, the configured value will be dynamically rendered in the component. Any future changes to the value in the Language Override settings will be reflected immediately across all instances where the key is used.