Best Practice to Store ConfigurationĀ 

This guide proposes the best practice on how to keep the environment or environment-related keys outside of the project across multiple environments.

  1. Create a new project titled ā€œConfigurationā€ within each environment (Dev, Stage, Prod). This is the project that we will not be moving whenever publishing our real project.

  2. Open the Configuration project.

  3. Under Develop > Schema create a new Schema and a name for it. In this example, we will name it ā€œSettings.ā€ We will set it as dynamic data with one field.

  4. This will hold the key value pair between Dev, Stage, and Production.

  5. Now we will go to Report > Data > Settings > and create a content block and a name for it. For this example, we will call it ā€œSettings A.ā€

    1. This is the key value pair we will keep here and what we will keep the same across all of the environments.

    2. You can add as many key values here as you want.

  6. Now we need to make sure this Configuration project is created with all of the same Schema and Data settings we have just created across Dev, Stage, and Production.

    1. The key is very important - we need to keep the same key across all of the same environments.

  7. To use it, letā€™s go into Experience Designer of the project you are trying to set up and we will be adding in the following nodes.

    1. Add an Inject node and set it to after 0.1 as we want it to be loaded as fast as possible.

    2. Then add a Function node and name it ā€œSet Model." Set the key to the schema key

    3. Add a Dynamic Data Manager node and program into the Settings

      1. Make sure the content name is the sameĀ as the one we have created

    4. Add another Function node and title it ā€œSet to Global context.ā€ This is where we will set Settings into the Global context for Experience Designer

      1. We recommend only one settings content so that the below code will only return one. Otherwise, make sure the correct settings item name is used.

        var settings = _.get(msg, 'data.dynamicData.result[0].payload', {});
      2. We will create a key in global setting called ā€œConfig Settingā€ and store the settings that we have to retrieve so that we can use it whenever we need to.

        global.set("CONFIG_SETTING", settings);
  8. Letā€™s test it to see if it is working. Insert an Inject node and a Function node to Check Config.

Now when we click on this, it will pull the settings weā€™ve created as part of the content under the settings we have created within the Configuration project.

If you change the settings within the Configuration project, it will only display if you deploy the global context again.

Ā