Wednesday 8 January 2014

Dynamic Customization in Theme via Theme Settings

Liferay provides rapid development feature for its theme.
Many time we may need some part of theme on need bases, timely changeable features.
For Example, say back ground images of portal should be customizable/changeable
on run-time. or you need customized/changeable menu on run-time.
 
This is achievable by theme settings in liferay-hook.xml of developed theme. 
 <?xml version="1.0"?>  
 <!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 6.1.0//EN"  
 "http://www.liferay.com/dtd/liferay-look-and-feel_6_1_0.dtd">  
 <look-and-feel>  
      <compatibility>  
           <version>6.1.0+</version>  
      </compatibility>  
      <theme id="example" name="Example">  
            <settings>  
           <setting key="image" type="text" configurable="true" value="image.png" />  
                <setting key="navigation-menu" type="select" configurable="true" value="mega-menu" options="mega-menu,default-menu,custom"/>  
      </settings>  
      </theme>  
 </look-and-feel>  
 
Above setting attributes will be available in interface so you can set it anytime.
Now, in your theme's vm file, you may want to have custom view based on these settings.
You would require to check values of these settings, below is the code snippet to fetch those 
setting.
 #set ($theme_settings = $themeDisplay.getThemeSettings())  
 $theme_settings.getProperty('Image')   
 $theme_settings.getProperty('navigation-menu')   
You can have if else conditions based on value of settings to customize your view.
Hope this would help you. 
Regards, 
 
 

4 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. I accidentally deleted your question. What do you mean by liferay theme or code.?
    This blog is about having configurable item for customization in custom theme and fetching it in velocity file of custom theme.

    ReplyDelete
  3. Your posts is really helpful for me.Thanks for your wonderful post. I am very happy to read your post. It is really very helpful for us and I have gathered some important information from this blog. liferay training in hyderabad

    ReplyDelete