Configuration patch file examples
The following examples of patch syntax illustrate how patching affects configuration. All examples show the original configuration, then the patch files, and finally the configuration after the patch files have been merged with the Sitecore.config file.
The examples illustrate:
To customize your configuration, you can use these examples of patch syntax to help you add or change configuration settings.
To use the patch and set namespaces, declare them at the beginning of the patch file as part of the <configuration> setting:
Merging configurations
Configurations from different patch files are merged in the order the patch files are processed.
The configuration used at runtime is:
Inserting an element before a specific element
You can insert a configuration element before a specific element. This example adds a processor before the processor with the test2 type, regardless of the position of test2 in the configuration:
The configuration used at runtime is:
Inserting an element after a specific element
You can insert a configuration element after a specific existing element. This example inserts a processor after the processor with the test2 type, regardless of the position of test2 in the configuration:
The configuration used at runtime is:
Adding or updating an attribute
You can add a new attribute or update the value of an existing attribute. If the attribute already exists, its existing value is replaced by the value from the patch file. If the attribute does not already exist in mysite, it is added to mysite. You can use either the patch namespace or the set namespace to achieve this effect.
This example adds the domainPath attribute to the mysite site, sets it to /home, and changes the virtualFolder attribute to /sitecore modules/web:
This patch file uses the patch namespace to change the attributes:
This patch file uses the set namespace to achieve the same result:
The final result is the same for both patch files. The configuration used at runtime is:
Deleting an element
You can delete a configuration element using patch:delete. Specify the name attribute for the element node in order to identify the element to remove.
Take care when using patch:delete because it removes the specified element and all its attributes from the configuration at runtime.
For example, this is the given Sitecore config:
The corresponding patch config deletes element "b":
The configuration used at runtime is:
If the element doesn't have a name attribute, you can list the element to remove and all its attributes, and include the patch:delete element. For example, this is the configuration file:
And this is the corresponding patch file:
The resulting configuration at runtime is:
Replacing the value of an element
Use the patch:instead attribute to specify that the selected element should be inserted instead of a sibling element. Unlike patch:before and patch:after, this attribute allows you to completely replace the original node or element.
The syntax is:
<processor type="CustomC, CustomA" patch:instead="*[@type='Sc, Sc']" />
The configuration used at runtime is: