Sitecore补丁 - 添加网站

Nil*_*Pun 5 patch sitecore 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>
Run Code Online (Sandbox Code Playgroud)

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

谢谢.

Jan*_*ink 8

如果要修补没有属性的节点,可以选择要编译的节点的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>
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)

  • 完美,正是我所追求的。谢谢。 (2认同)

Mar*_*lak 5

您不需要使用任何patch:deletepatch:instead.您只需要为name<site>标记添加属性,以便Sitecore将它们视为单独的网站定义.

以下是一些进一步的解释:配置外部配置文件的修补系统

创建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>
Run Code Online (Sandbox Code Playgroud)

另一个选项是使用一些其他标记而不是<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>
Run Code Online (Sandbox Code Playgroud)