• Liferay Theme Settings

    Posted on April 5, 2015 by Hamidul Islam in Liferay.



    Liferay Theme Settings allow us to configure theme in the run time. We can define liferay theme settings for a custom theme and configure theme. Liferay theme settings are defined as key-value pairs in the liferay-look-and-feel.xml file of the theme.Below is the syntax of  liferay theme settings

    Liferay Theme Settings Syntax

    		<setting key="my-setting1" value="my-value1" />
    		<setting key="my-setting2" value="my-value2" />

    We can access liferay theme settings like below


    Why we need Theme Settings?

    Suppose we have developed a theme. As we know that Liferay Theme is a collections of css, templates, js and images. A theme has a header, footer etc. Consider for some reason we need similar theme that we have developed except the footer is different. So are we going to develop another theme only for different footer? The answer No. Because liferay already provides solution for it.

    A theme is packaged as war file which is hot deploy able. That means one war contains only one theme. But its also possible to give different names for a single theme and it will act like a different themes when its deployed. 

    How to add theme settings?

    Open your liferay-look-and-feel.xml file and modify it like below

    <?xml version="1.0"?>
    <!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 6.2.0//EN" "http://www.liferay.com/dtd/liferay-look-and-feel_6_2_0.dtd">
    	<theme id="sample" name="Sample Theme">
    			<setting key="theme-id" value="sample" />
    	<theme id="blog" name="Blog Theme">
    			<setting key="theme-id" value="blog" />

    Be careful

    While adding theme settings or adding different id we should not change the original theme id. For example when we create theme by Plugin SDK or Liferay IDE a theme id will be created on the basis of input to IDE or Plugin SDK. We can keep the original theme id unchanged and add other theme id/settings according to our requirements.

     As soon as we deploy the theme we will notice that  2 themes are deployed.


    See the above. There are two new themes are available. Is not it cool. Whenever we will apply the theme, the theme settings will be also applied. Consider we have applied Blog Theme. For blog theme check the settings in the above liferay-look-and-feel.xml and its 

    <setting key="theme-id" value="blog" />

    Now we can access this settings in the VM file as
    #set ($theme_id = $theme.getSetting("theme-id"))

    Now we can write our own logic like

    	#if($theme_id == 'sample')
    		do something for sample
    	#elseif($theme_id == 'blog')
    		do something for blog

One Response so far.

  1. Aaftab says:

    As I have mentioned, it’s the first proliferay book tutorial I read almost 2 monts. I fell in love with the book and liferay programming, I believe it’s a good one for starters...Nice tutorials..

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.