13Apr, 2020
Understanding Sitecore 9 Configuration Layers
With Sitecore 9 we have a great new feature, which is Configuration Layers. These layers allow for the control and separation of config files, such as keeping your custom configs away from the Out-of-the-box ones. This is, and has always been recommended practice, and layers make it easier to control.
Configuration Layers are defined in \App_Config\Layers.config, where config files and folders containing config files are specified in the order we need them to be (no more “ZZZ” config folders!). The load orders are set here by use of the loadOrder element, and if one is not set Sitecore will fall back to its alphabetical loading of folders then files. Also, if a config file is not specified the configs are all loaded alphabetically.
<layer name="Custom" includeFolder="/App_Config/Include/"> <loadOrder> <add path="Forms" type="Folder" /> <add path="GeoIp" type="Folder" /> <add path="Security/FormValidation.config" type="File"/> </loadOrder> </layer>
In this example all files in the Forms and GeoIp folders will be loaded, then Security/FormValidation.config and then the rest of the Security folder. I would personally try to avoid changing the layers.config file at all as to avoid issues with upgrades and instead use the Helix folders (seen below).
The Layers
So, let's look at these layers! Out of the box, the default usage of Layers.config are defined as:
- Sitecore - The first and clearly largest of all layers, you will see the paths to about 60 folders which contain all the standard config files used to run Sitecore. These should not be changed as doing so will likely cause issues with Sitecore, and if you find you want to modify this area you should revisit what you're trying to accomplish.
- Modules - This is empty OOB, and would be used to support Sitecore Modules. Similar to Sitecore Layer, this should not be changed.
- Custom - This is where you would conventionally place your custom configs. The standard Helix pattern is ready for you with the three sub folders being Foundation, Feature, Project.
- Environment - Last but certainly not least we've got the Environment layer, where you can drop in configs to modify behaviour such as logging and what have you.
Sitecore will load the configs in the root of \App_Config\ as is tradition, and then the four layers above in the order listed.
Disabling Layers or Files
Finally, you can disable a Layer, Folder or File by setting the Mode attribute to it just like this:
<layer name="Custom" includeFolder="/App_Config/Include/"> <loadOrder> <add path="Forms" type="Folder" mode="off" /> <add path="GeoIp" type="Folder" /> <add path="Security/FormValidation.config" type="File" mode="off" /> </loadOrder> </layer>
The first config folder and specified file will not be used.
Viewing Layers
Want to see this all in action? Go to