Adding custom attribute to theme policy

Follow these steps if you want to add renderTestAttribute custom attribute to the theme policy

  • The root theme policy which is the first <policy> element node in the exported policies must have the renderTestAttribute attribute as well as lock attribute so add theme to theme policy like this.

    <policyValue
    Name="renderTestAttribute"
    Factory="com.ibm.wps.policy.parse.BooleanFactory">
    <value>true</value>
    </policyValue>
    <policyValue
    Name="renderTestAttributeLock"
    Factory="com.ibm.wps.policy.parse.BooleanFactory">
    <value>false</value>
    </policyValue>


  • By default every theme policy will inherit values from the root theme policy, so if you want a policy which requires different value of renderTestAttribute then true then add one attribute to that theme policy like this

    <policyValue
    Name="renderTestAttribute"
    Factory="com.ibm.wps.policy.parse.BooleanFactory">
    <value>false</value>
    </policyValue>


  • Inside your code you should use value of the renderTestAttribute to generate different content like this

    <% boolean isTestAttribute = themePolicy.getValueAsBoolean("renderTestAttribute", false);
    if(isTestAttribute){%>
    <p> Display this paragrah if renderTestAttribute is true. </p>
    <%}%>


No comments: