Expanded Links

Expanded Links

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Links.LinkManager
  • Sitecore.Data.Items.Item

Expanded Links C# Web Control Code

Sitecore.Data.Items.Item item = this.GetItem();
if (item == null) return;

string sources = item.Fields["Info"].Value;
//allow focus on the link by removing the first 823 characters from the rich text field display
string notes = sources.Substring(824);
string expandedLinks = Sitecore.Links.LinkManager.ExpandDynamicLinks(notes);

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(); //Div

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}", "Original Rich Text Field", "<br/><b>" + notes + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Expanded Dynamic Links", "<br/><b>" + expandedLinks + "</b>");
output.Write("<hr/>");
output.Write("{0}", "Use the mouse to point to each link and view the URL in the status bar at the bottom of the window");

output.RenderEndTag(); //Div

Notes

  • Sitecore.Links.LinkManager.ExpandDynamicLinks(string) is a static method
  • It transforms GUID references in RTE fields to friendly URLs
  • See the Link Management section for more link coding examples