Display Item Fields

Display Item Fields

Fields

  • Areas within which the data entered into the system is controlled
  • The data template associated with an item defines which fields it has Grouped into Sections
  • The section and field names provided in the template match those shown in the Content Editor
  • Used to organize and control the amount and type of data entered into the system:
    • Organized by their field type
    • The field type corresponds to the editing control provided in the Content Editor

Controls featured in this example:

  • Sitecore Web Control
  • XSLT Rendering

Classes featured in this example:

  • Sitecore.Collections.FieldCollection
  • Sitecore.Context
  • Sitecore.Data.Fields.Field
  • Sitecore.Data.Items.Item

Display Item Fields C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;
item.Fields.ReadAll();
Sitecore.Collections.FieldCollection fields = item.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: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.Ol);

foreach (Sitecore.Data.Fields.Field field in fields)
{
    if (!field.Name.StartsWith("__"))
    {
        output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
        output.Write("{0}: {1}", field.Name, field.Type);
        output.RenderEndTag(); //Li
    }
}

output.RenderEndTag(); //Ol
output.RenderEndTag(); //Div


Display Item Fields XSLT Rendering Code

<div style="font-weight:bold; width:100%; clear:both"> <br/>
<xsl:value-of select="'XSLT Rendering Real-time Output'"/>
</div>

<div style="font-size:small; width:100%; clear:both">
<p><b>Item: <sc:text field="title" select="$sc_item" disable-web-editing="true"/></b></p>
<ol>
<xsl:for-each select="$sc_item/fields/field">
<xsl:choose>
<xsl:when test="contains(./@key,'__')" >
      <!-- ignore system types -->
  </xsl:when>

<xsl:otherwise>
 <li><xsl:value-of select="./@key" />: <xsl:value-of select="./@type"/> </li>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</ol>
</div>


Display Item Fields C# Web Control Output

  1. breadcrumb title: Single-Line Text
  2. xslt demo: Rich Text
  3. csharp web control code: Rich Text
  4. info: Rich Text
  5. menu tooltip: Single-Line Text
  6. sources: Rich Text
  7. title: Single-Line Text
  8. menu title: Single-Line Text
  9. xslt rendering code: Rich Text
  10. sublayout demo: Rich Text
  11. web control demo: Rich Text
  12. qr code: Image
  13. tiny url: Single-Line Text
  14. csharp user control code: Rich Text
  15. related topics: Multilist
  16. image: Image
  17. theme: Droplist
  18. abstract: Multi-Line Text

Display Item Fields XSLT Rendering Output

  1. breadcrumb title: Single-Line Text
  2. xslt demo: Rich Text
  3. csharp web control code: Rich Text
  4. info: Rich Text
  5. menu tooltip: Single-Line Text
  6. sources: Rich Text
  7. title: Single-Line Text
  8. menu title: Single-Line Text
  9. xslt rendering code: Rich Text
  10. sublayout demo: Rich Text
  11. web control demo: Rich Text
  12. qr code: Image
  13. tiny url: Single-Line Text
  14. csharp user control code: Rich Text
  15. related topics: Multilist
  16. image: Image
  17. theme: Droplist
  18. abstract: Multi-Line Text