Show Multiline Text

Show Multiline Text

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 Multiline Text 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 mltFld = item.Fields["example multi-line text"];
if (mltFld == 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}", mltFld.InnerField.DisplayName + " Field Value", "<b>" + mltFld.Value + "</b>");
output.RenderEndTag(); //Div


Show Multiline Text 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 Multi-Line Text Field Value: '"/>
<!-- can also use <sc:text -->
<b><sc:memo field="example multi-line text" select="$simpleFields" /></b><br/>
</div>


Show Multiline Text C# Web Control Output

Example Multi-Line Text Field Value: 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.


Show Multiline Text XSLT Rendering Output

Example Multi-Line Text Field Value: 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.