Managing configuration (Java)

Web site elements may require custom configuration, for example an API key for an external service or a date format to use when rendering dates. Configuration is centrally managed and published from the Content Manager so that Web applications do not require site-by-site manual configuration on localization.

Procedure

  1. Create a new configuration Component:
    1. Navigate to where you want to create the Component: using the recommended Folder structure, go to Building Blocks/Settings/ModuleName/Role, where ModuleName is the name of your Module, and Role is one of Developer, Site Manager or Editor.
    2. Create a Component based on a custom Schema or use the General Configuration generic Schema (multi-value name/value pairs).

      For example, if you are using a tracking system for Special Offers which requires a site identifier as a parameter for measuring click throughs, store the identifier in a configuration Component. In Building Blocks/Settings/MyCompanyExamples/SiteManager, create a Component based on the General Configuration Schema and add a new value:

      • Name is siteKey
      • Value is MyCompanySite1
    3. Open the Main Module Configuration Component Once the component and link to this Component in the Further Configuration field.
      If you do not have a Main Module Configuration Component, create one in Building Blocks/Modules/ModuleName/Admin based on the Module Configuration Schema in: and give it the same name as the Module as described in the section on setting up Content Manager structure.
  2. Refresh the Web application settings:
    1. Go to the Home/_System Structure Group.
    2. Select the Publish Settings Page and click Publishing > Publish.
    3. Go to your Web application and enter the URL /admin/refresh refresh the cache and reload the settings in the Web application.
  3. Reading configuration in the Web application:

    You can write out a configuration value in views using the Localization.getConfiguration method. For example, update your SpecialOffer View link as follows to write out your siteKey config setting:

    <a onclick="trackOfferClick('${localization.getConfiguration('mycompanyname.sitekey')}','${entity.id}')" href="${entity.link}" class="btn btn-primary" ${markup.property(entity, "link")}>More Info</a>