Get Aliases

Get Aliases

Alias

  • An item in the Content Tree that provides an alternative URL for another content item
  • Contains a Linked Item field that usually specifies a link to another Content Tree item
  • Sitecore does not redirect the browser; it just displays the link item

Aliases Folder

  • Folder item in the Content Tree where Sitecore stores alias items
  • The fully qualified path to the Aliases folder is /sitecore/system/Aliases

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil
  • Sitecore.TemplateIDs
  • System.Linq
  • System.String

Aliases C# Web Control Code

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

Sitecore.Data.Database db = Sitecore.Context.Database;
string query = System.String.Format("//*[@@templateid='{0}']", Sitecore.TemplateIDs.Alias);
Sitecore.Data.Items.Item[] descendants = db.SelectItems(query);
if (descendants == null) return;
var sortedList = (from entry in descendants orderby entry.DisplayName ascending select entry);

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);
string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
//using : for colon and   for space
output.Write("{0}: {1}", "Item", displayName);
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
output.Write("{0}", "Displaying Filtered Descendants");
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item descendant in sortedList)
{
    i++;
    output.Write("{0}", descendant.DisplayName + "<br/>");
    //only display first ten items
    if (i >= 10) break;
}

output.RenderEndTag(); //Div

Aliases C# Web Control Output

Displaying Filtered Descendants

ContentAuthorsFeed
DevelopersFeed
MarketersFeed
ProjectLeadsFeed
SiteAdminsFeed
versionmanager
WebDesignersFeed

Sources