Sitecore Patch - Add website
Asked Answered
T

4

5

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.

Tarry answered 20/11, 2015 at 5:39 Comment(0)
F
9

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>
Fallonfallout answered 20/11, 2015 at 8:32 Comment(2)
In the App_Config\Include\Sitecore.ExperienceExplorer.config line 162 from Sitecore 8.1 you can found a advanced example of using ./text()Fallonfallout
pefect, exactly what I'm after. Thank you.Tarry
P
5

You don't need to use any patch:delete or patch:instead. You just need to add name attribute to your new <site> tags so Sitecore will treat them as a separate site definitions.

Here is some further explanation: Config patching system for the external config files

Create App_config\Include\My.Site.Definition.config file with content:

<sitecore>
  <sites>
    <site name="mysite" patch:before="site[@name='website']"
        ... />
  </sites>
  <events>
    <event name="publish:end">
      <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
        <sites hint="list">
          <site name="mysite">mysite</site>
        </sites>
      </handler>
    </event>
    <event name="publish:end:remote">
      <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
        <sites hint="list">
          <site name="mysite">mysite</site>
        </sites>
      </handler>
    </event>
  </events>
</sitecore>

The other option would be to use some other tags instead of <site> tag, cause when the parent tag contains hint="list" attribute, it treats all the children tags as items for that list. You would need to make sure that every tag is unique. You can use it like that:

<event name="publish:end:remote">
  <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
    <sites hint="list">
      <site1>mysite</site1>
      <othersite>othersite</othersite>
    </sites>
  </handler>
</event>
Palmapalmaceous answered 20/11, 2015 at 8:48 Comment(1)
is right, a unique tag needs to be added and order does not matter for the cache clearer.Hardison
R
0

You don't have to patch list of sites. You need to add all your websites one by one.

    <event name="publish:end:remote">
        <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
            <sites hint="list">
                <site>SiteOne</site>
                <site>Sitetwo</site>
                     ...
                <site>SiteN</site>
            </sites>
        </handler>
    </event>
Revile answered 20/11, 2015 at 5:52 Comment(4)
But we don't want to store any of the sitecore configuration in our solution. Is there way to preserver website and add more sites?Tarry
What do you mean : "we don't want to store sitecore configuration in our solution"? Normally you have in your solution app_config folder that is copied to a destination folder, but depends from solution to solution.Revile
I meant we should only patch the sitecore configuration files so that upgrades are easierTarry
+1 @myagdi it's really best to leave the standard conf in its pristine state and use patches to effect changes. I can say without hyperbole that this makes upgrading literally a billion times easier. Literally.Binge
A
0

This has been already answered but adding to the answer above- while patching the sites you don't need to add other element attributes but only the ones you are patching.

<sitecore>
<events>
  <!-- Html Cache clear on publish events -->
  <!-- Force FULL cache clear on publish-->
  <event name="publish:end">
    <handler>
      <sites>
        <site name="customSite">customSite</site>
      </sites>
    </handler>
  </event>
  <!-- Html Cache clear on publish events -->
  <!-- Force FULL cache clear on publish-->
  <event name="publish:end:remote">
    <handler>
      <sites>
        <site name="customSite">customSite</site>
      </sites>
    </handler>
  </event>
</events>

Amphitrite answered 16/11, 2019 at 1:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.