No Standard Values

No Standard Values

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.Data.Items.TemplateItem
  • Sitecore.ItemIDs
  • Sitecore.TemplateIDs
  • System.Linq
  • System.String

No Standard Values C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item templateRoot = db.GetItem(Sitecore.ItemIDs.TemplateRoot);
if (templateRoot == null) return;
string templateRootPath = templateRoot.Paths.Path;

string query = System.String.Format(templateRootPath + "//*[@@templateid='{0}']", Sitecore.TemplateIDs.Template);
Sitecore.Data.Items.Item[] templates = db.SelectItems(query);
if (templates == null) return;

var sortedList = (from entry in templates orderby entry.Paths.Path ascending select entry);

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);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "First Ten Templates that do not contain a Standard Values node");
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item template in sortedList)
{
    Sitecore.Data.Items.TemplateItem templateItem = new Sitecore.Data.Items.TemplateItem(template);
    Sitecore.Data.Items.Item stndValues = templateItem.StandardValues;
    if (stndValues == null)
    {
        i++;
        output.Write("{0}", template.Paths.Path + "<br/>");
        //only display first ten items
        if (i >= 10) break;
    }
}
if (i == 0)
    output.Write("{0}", "There are no templates without a Standard Values node");
           
output.RenderEndTag(); //Div


No Standard Values C# Web Control Output

First Ten Templates that do not contain a Standard Values node

/sitecore/templates/Redirect Module/Redirect Folder
/sitecore/templates/Redirect Module/Redirect Url
/sitecore/templates/System/Alias
/sitecore/templates/System/Analytics/Country
/sitecore/templates/System/Analytics/Dashboard/Dashboard Report
/sitecore/templates/System/Analytics/Organic Branded Keywords
/sitecore/templates/System/Analytics/Profile Key Control
/sitecore/templates/System/Analytics/Report
/sitecore/templates/System/Analytics/Report Schedule
/sitecore/templates/System/Analytics/ReportQuery