February 15, 2012

Config patching system for the external config files

This very good post http://www.thescrewballdivision.com/playing-with-sitecore-include-files explain the available commands for the patching very well so I will not copy it but I will add an important information.

When you need to add some informations in a tag the key used for the merge is the property name.

Example:

By default in the web.config you have this:
<event name="publish:end">
 <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
   <sites hint="list">    
      <site>website</site>
   </sites>
 </handler>
</event> 

And if you add this in a separated config file:
<event name="publish:end">
 <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
   <sites hint="list">    
     <site>mysite</site>
   </sites>
 </handler>
</event> 

The merged web.config will be:
<event name="publish:end">
 <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
   <sites hint="list">    
      <site>mysite</site>
   </sites>
 </handler>
</event> 

To avoid this and combine the two tags without removing the existing one you only have to add a name property in the site tag:
<event name="publish:end">
 <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
   <sites hint="list">    
      <site name="mysite">mysite</site>
   </sites>
 </handler>
</event> 

Like this you will have the expected result:
<event name="publish:end">
 <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
   <sites hint="list">  
      <site>website</site>
      <site name="mysite">mysite</site>
   </sites>
 </handler>
</event> 

No comments:

Post a Comment