Glasses on top of laptop keyboard

Patch delete Sitecore elements based on element content

Recently, I wrote about patching Sitecore instances for specific roles. During my research on how to do this, I was able to use a manner of Sitecore patching I had not previously known about. With a patch:instead, instead of targeting an attribute of the element you can actually target the contents of that element. (Thanks to @jammykam for that Stack Overflow post!)

Why is this useful?

Typically patch:instead is used to replace one value with another in the settings, but because of the matching capabilities of this syntax you can use this to patch:delete elements you couldn’t otherwise match against.

So, when you need to remove an element from the configurations that have multiple elements with no distinguishing characteristics, you can target the inner content instead to distinguish them.

Yummy Config example!

Below is a sample config file which can remove a <using> tag by targeting the text inside the using tag.

<?xml version="1.0"?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <ui>
      <usings>
        <!--Target based on text in the tag-->
        <using patch:instead="using[.='Sitecore.Social.Client.Wizards.AddNetworkAccount']">
          <patch:delete />
        </using>
      </usings>
    </ui>
  </sitecore>
</configuration>
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s