1
votes

How do I

  1. Add a Select Dropdown with custom values in the custom theme that I developed?
  2. Also need to set the default value of that select dropdown.
  3. Change some stuff in the theme based on this Select dropdown values.

I'm looking for code samples which achieve the above stuff.

1

1 Answers

1
votes

To answer the first and second questions:

  1. Add a Select Dropdown with custom values in the custom theme that I developed?
  2. Also need to set the default value of that select dropdown.

In liferay-look-and-feel.xml, add a select theme settings with the your keys

<look-and-feel>
    <compatibility>
        <version>6.2.0+</version>
    </compatibility>
    <theme id="theme-id" name="theme-id" >
        <settings>
            <setting type="select" configurable="true" 
                key="dropdown-title-key" 
                options="select-option-1,select-option-2"                   
                value="select-option-2" ></setting>
        </settings>
    </theme>    
</look-and-feel>

These keys should have corresponding Text Values in the Language_en_US.properties. This properties should be injected through a hook. Write a hook project and specify the following in liferay-hook.xml.

<?xml version="1.0"?>
<!DOCTYPE hook PUBLIC "-//Liferay//DTD Hook 6.2.0//EN" "http://www.liferay.com/dtd/liferay-hook_6_2_0.dtd">

<hook>
    <portal-properties>portal.properties</portal-properties>
    <language-properties>
        content/Language_en_US.properties
    </language-properties>
</hook>

In the content folder (which should be in classpath), enter the text for the keys specified in liferay theme settings in Language_en_US.properties file.

dropdown-title-key=Choose a value from the dropdown
select-option-1=This is Option 1
select-option-2=This is Option 2

To answer the third question:

  1. Change some stuff in the theme based on this Select dropdown values.

The changes are normally done in portal_normal.vm file of the theme on which the select dropdown theme setting is done.

#if($theme.getSetting("dropdown-title-key")=='select-option-1')
    ##Do Something Here
#elseif($theme.getSetting("dropdown-title-key")=='select-option-2')
    ##Do Something Else Here
#end