Search code examples
liferayliferay-theme

How can we share settings values across Liferay themes in same war


We have a one theme application with 2 themes packages in it.We need to share settings from one theme to the other.

<theme id="visual" name="visual-theme" >
        <settings>
            <setting key="service-unavailable" configurable="true" type="checkbox" value="false"></setting>
        </settings>
    </theme>

    <theme id="visual-home" name="visual-theme-home" >
        <settings>
            <setting key="h1-title-value" configurable="true" type="textarea" value="" ></setting>
            <setting key="service-unavailable" configurable="true" type="checkbox" value="false"></setting>
            <setting key="service-unavailable-message" configurable="true" type="textarea" value="Unavailable service"></setting>
        </settings>
    </theme>

We need service-unavailable-message setting to be available to visual-theme as default value, so that when set from visual-theme-home,it should be available to the other theme as well.


Solution

  • The settings are per theme, not per web application, thus the settings for some area with theme A will have no effect on anything with theme A. You'll have to use another technique for achieving this.

    When you use theme settings, you can set these values either per site or per page. In the later case, this would introduce yet another ambiguity.

    So one option you have is

    <theme id="visual" name="visual-theme" >
      <settings>
        <setting key="service-unavailable" configurable="true" type="checkbox" value="false"></setting>
        <setting key="service-unavailable-message" configurable="true" type="textarea" value="Unavailable service"></setting>
      </settings>
    </theme>
    
    <theme id="visual-home" name="visual-theme-home" >
      <settings>
        <setting key="h1-title-value" configurable="true" type="textarea" value="" ></setting>
        <setting key="service-unavailable" configurable="true" type="checkbox" value="false"></setting>
        <setting key="service-unavailable-message" configurable="true" type="textarea" value="Unavailable service"></setting>
      </settings>
    </theme>
    

    ...and duplicate the message whereever you need.

    Another option is to move service-unavailable-message to another place (as a more general configuration value, or looked up from some service. Just not as a theme setting.