Reset Renderings

Reset Renderings

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Collections.ChildList
  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Items.Item
  • Sitecore.Data.Items.TemplateItem
  • Sitecore.FieldIDs
  • Sitecore.SecurityModel.SecurityDisabler

Reset Renderings C# Web Control Code

Sitecore.Data.Database db = Sitecore.Context.Database;

Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home/developers");
if (item == null) return;

const string filter = ".//*[@@templatename='TIC-PermBuilderPage']";
Sitecore.Data.Items.Item[] descendants = item.Axes.SelectItems(filter);
if (descendants == null) return;

Sitecore.Data.Items.TemplateItem template1 = db.GetTemplate("TIC/PageTypes/TIC-CodeSnippet");
Sitecore.Data.Items.TemplateItem template2 = db.GetTemplate("TIC/PageTypes/TIC-ConfigSetting");
if (template1 == null || template2 == null ) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

using (new Sitecore.SecurityModel.SecurityDisabler())
{
    foreach (Sitecore.Data.Items.Item descendant in descendants)
    {
        Sitecore.Collections.ChildList children = descendant.GetChildren();
        foreach (Sitecore.Data.Items.Item child in children)
        {
if (child.TemplateID == template1.ID || child.TemplateID == template2.ID)
{
      
    Sitecore.Data.Fields.Field field = child.Fields[Sitecore.FieldIDs.LayoutField];
    if (!field.ContainsStandardValue)
    {
        child.Editing.BeginEdit();
        field.Reset();
        child.Editing.EndEdit();
    }
}
        }
    }
}

output.RenderEndTag(); //Div

C# Web Control Real-time Output

Item: Developers

Notes

  • There is no output for this web control
  • The web control is not bound to this page