Liferay Theme settings provides options to liferay portal administrator to modify page elements with out modifying / deploying any code. These theme settings can be configurable settings, which can be modified from configuration panel of theme.

Please check how to create Liferay theme and basic Liferay theme structure before continuing.

Liferay theme settings are defined in theme’s liferay-look-and-feel.xml file. These settings should be wrapped inside XML tag <settings>  and each individual setting is defined using <setting> tag.

following is an example of simple theme setting:

<settings>
  <setting key="my-key" value="my-value" />
</settings>

These <setting> tag contains key and value pair, along with optional parameters like:

  • configurable : Whether setting is configurable or a static setting.
  • type :  Specifies the data type of setting (checkbox, select, text, or textarea). Default data type is text if not provided.
  • options : If data type is of type select, this attribute will hold comma separated list of option values.

Configurable Theme Settings : We can make our custom theme settings configurable, to allow our theme to modify page elements based on configuration setting value from administrator panel .

Following is an example configurable theme setting. Here we have a theme setting, defined inside liferay-look-and-feel.xml file, which is configurable(attribute configurable = “true” is used) and having data type select with values true/false.

<setting key="show-page-title" configurable="true" 
 value="true" options="true,false" type="select" />

Now this setting is used to hide page title by using following code(Note: Here we have used velocity as template language). we are fetching the custom configuration setting value from liferay-look-and-feel.xml file and hide/ show page title based on setting value.

##Get setting value from liferay-look-and-feel.xml using key:
#set($show_page_title = $theme_display.getThemeSetting('show-page-title'))

##If setting value is 'true' show page title:
#if($show_page_title == 'true') 
 <h2 class="page-title">
   <span>$the_title</span>
 </h2>
#end

Following are the outputs:

with value setting as ‘false’ :

themeSettings1.PNG

with setting value as ‘true’ :

themeSettings2.PNG

 

Portal Defined Settings : Portal provides some default setting keys. Few of the available setting properties are : portlet borders, bullet styles, and the site name.

Here is an example of portlet borders setting. This setting is defined with the key “portlet-setup-show-borders-default” and can be used to show/ hide portlet borders. It can also be made configurable as shown below:

<setting key="portlet-setup-show-borders-default"
 configurable="true" value="true" type="checkbox" />

Following are the outputs:

with setting value checked :

themeSettings3.PNG

with setting value unchecked :

themeSettings4.PNG

Liferay theme settings is a very useful feature, which makes our theme configurable at live environment, without the requirement of code modification/ deployment of theme.

Check out all Liferay related posts.

Note: Version used: Liferay 6.2 + Apache Tomcat 7.