Sitecore补丁 - 添加网站

时间:2015-11-20 05:39:32

标签: sitecore patch sitecore8.1

我正在尝试在网站列表中添加网站名称,以便在publish:end:remote事件中清除HTML缓存。

<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>

然而,它没有按预期工作。我做谷歌搜索,并没有找到任何关于如何在元素之前或之后进行修补的内容。大多数示例都在/属性等之前。

感谢。

4 个答案:

答案 0 :(得分:6)

如果要修补没有属性的节点,可以选择要编译的节点的text()。之前或之后。看这个例子:

<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>

解决您问题的另一种方法。 通过删除补丁,您可以清除列表并从头开始构建列表。

<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>

答案 1 :(得分:5)

您无需使用任何patch:deletepatch:instead。您只需将name属性添加到新的<site>代码中,以便Sitecore将其视为单独的网站定义。

以下是一些进一步的解释:Config patching system for the external config files

创建包含内容的App_config\Include\My.Site.Definition.config文件:

<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>

另一个选项是使用一些其他标记而不是<site>标记,因为当父标记包含hint="list"属性时,它会将所有子标记视为该列表的项目。您需要确保每个标签都是唯一的。您可以这样使用它:

<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>

答案 2 :(得分:0)

您无需修补网站列表。您需要逐个添加所有网站。

    <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>

答案 3 :(得分:0)

已经回答了这个问题,但在上面的答案中添加了答案-在修补站点时,您不需要添加其他元素属性,而只需添加要修补的元素。

<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>