Show Integer Field

Show Integer Field

Controls featured in this example:

  • Sitecore Web Control
  • XSLT Rendering

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Fields.TextField
  • Sitecore.Data.Items.Item

Show Integer Field C# Web Control Code

//get Simple Fields metadata item from context 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.TextField intFld = item.Fields["example integer"];
if (intFld == 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}", "Item", item.DisplayName);
output.RenderEndTag(); //P

output.Write("{0}&#58;&#160;{1}", intFld.InnerField.DisplayName + " Field Value", "<b>" + intFld.Value + "</b>");
output.RenderEndTag(); //Div


Show Integer Field XSLT Rendering Code

<xsl:variable name="simpleFields" select="sc:item('{EC44470F-FF45-4023-95C2-EC886FD33D0C}',.)" />

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

<div style="font-size:x-small; width:100%; clear:both">
<p><b>Item: <xsl:value-of select="$simpleFields/@name"/></b></p>
<xsl:value-of select="'Example Integer Field Value: '"/>
<!-- alternative to <xsl:value-of select="sc:fld('example integer',$simpleFields)" /> -->
<b><sc:text field="example integer" select="$simpleFields" /></b><br/>
</div>


Show Integer Field C# Web Control Output

Example Integer Field Value: 997


Show Integer Field XSLT Rendering Output

Example Integer Field Value: 997

Notes

  • Sitecore does not recommend the use of XSL to process Integer fields

Sources