Get Standard Values

Get Standard Values

Actions perfomed on Data Templates

  • To set icons
  • To assign sections and fields to data templates
  • To assign base templates for template inheritance

Actions performed on Standard Values

  • To assign default field values
  • To assign Insert Options
  • To bind content to presentation components
  • To assign workflows

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Collections.FieldCollection
  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Items.Item
  • Sitecore.Data.Items.TemplateItem
  • System.String


Standard Values C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.TemplateItem template = db.GetTemplate(item.TemplateID);
if (template == null) return;

Sitecore.Data.Items.Item templateSV = template.StandardValues;
if (templateSV == null) return;

Sitecore.Collections.FieldCollection fields = templateSV.Fields;
if (fields == 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);
//using : for colon and   for space
output.Write("{0}: {1}", "Parent Item", item.DisplayName);
output.RenderEndTag(); //P
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}: {1}", "Template", template.DisplayName);
output.RenderEndTag(); //p

fields.ReadAll();
foreach (Sitecore.Data.Fields.Field field in fields)
{
    //remove Standard fields from Sitecore base templates
    if (!field.Name.StartsWith("__"))
    {
        if (!System.String.IsNullOrEmpty(field.Value)) 
output.Write("{0}&#58;&#160;{1}", "<b>" + field.Name, field.Value + "</b><br/>");
    }
}
        
output.RenderEndTag(); //Div


Standard Values C# Web Control Output

Template: TIC-CodeSnippet

Breadcrumb Title: $name
Menu Tooltip: $name
Title: $name
Menu Title: $name
Theme: Theme1