• Liferay Theme Settings

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

    liferay-theme-settings


    aim

    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

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

    We can access liferay theme settings like below

    	$theme.getSetting("my-setting1")
    	$theme.getSetting("my-setting2")
    


    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">
    
    <look-and-feel>
    	<compatibility>
    		<version>6.2.1+</version>
    	</compatibility>
    	<theme id="sample" name="Sample Theme">
    		<settings>
    			<setting key="theme-id" value="sample" />
    		</settings>
    	</theme>
    	<theme id="blog" name="Blog Theme">
    		<settings>
    			<setting key="theme-id" value="blog" />
    		</settings>
    	</theme>
    </look-and-feel>
    

    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.

    available-themes

    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
    	#end
    

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

Your email address will not be published. Required fields are marked *

Are you human? * Time limit is exhausted. Please reload CAPTCHA.

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

Close