【问题标题】:How to programmatically add conditions to a rendering in Sitecore 8如何以编程方式向 Sitecore 8 中的渲染添加条件
【发布时间】:2015-12-08 01:11:33
【问题描述】:

我以编程方式将渲染添加到项目占位符。 代码如下所示:

var newRendering = new Sitecore.Layouts.RenderingDefinition();
newRendering.ItemID = "{SUBLAYOUTID}";
newRendering.Placeholder = "PLACEHOLDER";
newRendering.Datasource = "{DATASOURCEID}";

//Adds the new RenderingDefinition to the device renderings.
device.AddRendering(newRendering);

这行得通。我也在尝试添加一个条件,但不知道如何。 有人有想法吗?

【问题讨论】:

    标签: c# asp.net content-management-system sitecore sitecore8


    【解决方案1】:

    您应该使用newRendering.Rules 属性,但不幸的是它是XmlElement 类型,因此生成正确的值并不容易,除非您想从另一个渲染中复制条件。

    Rules 属性的示例值为:

    <ruleset>
      <rule uid="{40E52E8C-39EB-40A2-BBE4-985F7421EDEC}" p2:name="Condition Name" xmlns:p2="s">
        <conditions>
          <condition uid="0BE3D7A7B0C64002A02AC1205567C43E" p2:id="{8A9B001F-FB59-4F0F-B3F3-C6C5360ED451}" p2:Now="20150128T143000" />
        </conditions>
        <actions>
          <action uid="295430EFD38B40A7AE307A5C7751F0C1" p2:id="{0F3C6BEC-E56B-4875-93D7-2846A75881D2}" p2:DataSource="{86902BC8-BFE6-4376-87B0-81EFE87BDE34}" />
        </actions>
      </rule>
      <rule uid="{00000000-0000-0000-0000-000000000000}" p2:name="Default" xmlns:p2="s">
        <conditions>
          <condition uid="7EF464FFDF5E45FCA84732B375F2FA3A" p2:id="{4888ABBB-F17D-4485-B14B-842413F88732}" />
        </conditions>
        <actions />
      </rule>
    </ruleset>
    

    【讨论】:

    • 现在只复制一个条件就足够了。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-13
    • 2012-08-30
    • 1970-01-01
    • 2020-08-12
    • 2021-12-11
    • 2018-07-10
    相关资源
    最近更新 更多