Rich Text Properties

Rich Text Properties

Rich Text Fields

  • Store field values as XML-encoded HTML (XHTML)
  • Supported by <sc:text> web control in declarative markup
  • Supported by Sitecore.Data.Fields.HtmlField class in Sitecore API
  • Field values can be displayed by the FieldRenderer.Render() method and FieldRenderer control
  • Natively supports displaying field values in the Page Editor

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.HtmlField
  • Sitecore.Data.Items.Item
  • Sitecore.MainUtil

C# Web Control Code

//get Simple Fields metadata item from master database using item guid
Sitecore.Data.Database db = Sitecore.Context.Database;
Sitecore.Data.Items.Item item = db.GetItem("{EC44470F-FF45-4023-95C2-EC886FD33D0C}");
if (item == null) return;

Sitecore.Data.Fields.HtmlField htmlFld = item.Fields["example rich text"];
if (htmlFld == 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 &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Field", htmlFld.InnerField.DisplayName);
output.RenderEndTag(); //P

output.Write("Can Read? " + "<b>" + htmlFld.InnerField.CanRead.ToString() + "</b><br/>"); 
output.Write("Can Write? " + "<b>" + htmlFld.InnerField.CanWrite.ToString() + "</b><br/>"); 
output.Write("Contains Standard Value? " + "<b>" + htmlFld.InnerField.ContainsStandardValue.ToString() + "</b><br/>"); 
output.Write("Definition: " + "<b>" + htmlFld.InnerField.Definition.Name + "</b><br/>"); 
output.Write("Description: " + "<b>" + htmlFld.InnerField.Description + "</b><br/>"); 
output.Write("Display Name: " + "<b>" + htmlFld.InnerField.DisplayName + "</b><br/>"); 
output.Write("Has Blob Stream? " + "<b>" + htmlFld.InnerField.HasBlobStream.ToString() + "</b><br/>"); 
output.Write("Has Value? " + "<b>" + htmlFld.InnerField.HasValue.ToString() + "</b><br/>"); 
output.Write("ID: " + "<b>" + htmlFld.InnerField.ID.ToString() + "</b><br/>"); 
output.Write("Contains Inherited Value? " + "<b>" + htmlFld.InnerField.InheritedValue + "</b><br/>"); 
output.Write("Is Blob Field? " + "<b>" + htmlFld.InnerField.IsBlobField.ToString() + "</b><br/>"); 
output.Write("Has Been Modified? " + "<b>" + htmlFld.InnerField.IsModified.ToString() + "</b><br/>"); 
output.Write("Key: " + "<b>" + htmlFld.InnerField.Key + "</b><br/>"); 
output.Write("Language: " + "<b>" + htmlFld.InnerField.Language.Name + "</b><br/>"); 
output.Write("Name: " + "<b>" + htmlFld.InnerField.Name + "</b><br/>"); 
output.Write("Reset Blank On? " + "<b>" + htmlFld.InnerField.ResetBlank.ToString() + "</b><br/>"); 
output.Write("Section Name: " + "<b>" + htmlFld.InnerField.Section + "</b><br/>"); 
output.Write("Sort Order: " + "<b>" + htmlFld.InnerField.Sortorder.ToString() + "</b><br/>"); 
output.Write("Shared? " + "<b>" + htmlFld.InnerField.Shared.ToString() + "</b><br/>"); 
output.Write("Source: " + "<b>" + htmlFld.InnerField.Source + "</b><br/>"); 
output.Write("Title: " + "<b>" + htmlFld.InnerField.Title + "</b><br/>"); 
output.Write("Tooltip: " + "<b>" + htmlFld.InnerField.ToolTip + "</b><br/>"); 
output.Write("Translatable? " + "<b>" + htmlFld.InnerField.Translatable.ToString() + "</b><br/>"); 
output.Write("Type: " + "<b>" + htmlFld.InnerField.Type + "</b><br/>"); 
output.Write("Type Key: " + "<b>" + htmlFld.InnerField.TypeKey + "</b><br/>"); 
output.Write("Unversioned? " + "<b>" + htmlFld.InnerField.Unversioned.ToString() + "</b><br/>"); 
output.Write("Validation Regex: " + "<b>" + htmlFld.InnerField.Validation + "</b><br/>"); 
output.Write("Validation Message: " + "<b>" + htmlFld.InnerField.ValidationText + "</b><br/>"); 
output.Write("Value: " + "<b>" + htmlFld.InnerField.Value + "</b>");

output.RenderEndTag(); //Div


C# Web Control Real-time Output

Field: Example Rich Text

Can Read? True
Can Write? True
Contains Standard Value? False
Definition: Example Rich Text
Description: 
Display Name: Example Rich Text
Has Blob Stream? False
Has Value? True
ID: {D274C365-32EE-40DA-B6E2-2ED170DDC69F}
Contains Inherited Value?

A rich text field can contain...


Is Blob Field? False
Has Been Modified? False
Key: example rich text
Language: en
Name: Example Rich Text
Reset Blank On? False
Section Name: Simple Field Types
Sort Order: 1000
Shared? False
Source: 
Title: 
Tooltip: 
Translatable? True
Type: Rich Text
Type Key: rich text
Unversioned? False
Validation Regex: 
Validation Message: 
Value:

A rich text field can contain...