Default Formats

Default Formats

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.MainUtil

Default Formats C# Web Control Code

//get Simple Fields metadata item from context database using item path
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/TIC-Meta/FieldsDemos/Simple Fields");
if (db == null || item == null) return;

Sitecore.Collections.FieldCollection fields = item.Fields;
if (fields == null) return;
fields.ReadAll();

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}", "Fields Default Display Formatting");
output.RenderEndTag(); //P

foreach (Sitecore.Data.Fields.Field field in fields)
{
    //only care about fields that are not null and if field name contains "Example"
    if (field != null && field.Name.IndexOf("Example") > -1)
    {
        //display field value and add linebreak 
        output.Write(field.DisplayName + " Field: <b>" + field.ToString() + "</b><br/>"); 
        output.Write("<hr/>");    }

}
output.RenderEndTag(); //Div


Default Formats C# Web Control Output

Fields Default Display Formatting

Example Datetime Field: 20100705T033000

 

Example Date Field: 10/4/2013 3:15:21 PM

 

Example File Field:

 

Example Image Field:

 

Example Password Field: password

 

Example Rich Text Field:

A rich text field can contain...

 

Example Number Field: 999.97

 

Example Word Document Field: {8A4E61F1-1120-4B4B-A2DE-17AA6CEF3A0B}00000651

00000129

 

This content

was created

using a

Word Add-on

to Internet

Explorer

 

 

Example Multi-Line Text Field: This raw text cannot fit on a single line. The multi-line text field enables users to view the first few lines of the content immediately. Additional lines can be viewed by using the scroll bar


Example Integer Field: 997

 

Example Checkbox Field: 1


Example Single-Line Text Field: This raw text can fit on a single line