Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitecore Patch - Add website

I'm trying to add site name on list of sites so that HTML cache gets cleared on publish:end:remote event.

<event name="publish:end:remote">
  <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
    <sites hint="list">
      <site patch:after="*[@site]">mysite</site>
    </sites>
  </handler>
  <handler type="Sitecore.Publishing.RenderingParametersCacheClearer, Sitecore.Kernel" method="ClearCache"/>
</event>

However it isn't working as expected. I did googling and didn't find anything on how we can patch before or after an element. Most of the examples are on/before attribute etc.

Thanks.

like image 580
Nil Pun Avatar asked Nov 20 '15 05:11

Nil Pun


1 Answers

If you want to patch a node without attributes, you can select the text() of the node to compair. before or after. see this Example:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events timingLevel="custom">
      <event name="publish:end:remote">
        <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
          <sites>
            <site patch:before="site[./text()='website']">plop3</site>
          </sites>
        </handler>
      </event>
    </events>
  </sitecore>
</configuration>

A different approach to your issue. With a patch delete you can clear the list and build your list from scratch.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events timingLevel="custom">
      <event name="publish:end:remote">
        <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
          <sites hint="list">
            <patch:delete />
          </sites>
          <sites hint="list">
            <site>website</site>
            <site>anotherwebsite</site>
          </sites>
        </handler>
      </event>
      </events>
  </sitecore>
</configuration>
like image 143
Jan Bluemink Avatar answered Oct 28 '22 00:10

Jan Bluemink