Skip to content

Instantly share code, notes, and snippets.

@RyanABailey
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save RyanABailey/4039f100f60d99bd5b66 to your computer and use it in GitHub Desktop.

Select an option

Save RyanABailey/4039f100f60d99bd5b66 to your computer and use it in GitHub Desktop.
Sitecore breadcrumbs
Item currentItem = Sitecore.Context.Item; // Current sitecore item
BreadCrumbs.Current = currentItem.Fields["Title"].ToString(); // set current items title on breadcrumb object
currentItem = currentItem.Parent; // go to parent of current item
while (currentItem.ID != new ID(Items.ContentRootItem))
{
// add parent item to breadcrumb object (a list of parent items)
BreadCrumbs.Parents.Add(new Common.MenuItem
{
Link = Sitecore.Links.LinkManager.GetItemUrl(currentItem),
Text = currentItem.Fields["Title"].ToString()
});
currentItem = currentItem.Parent; // get parent of current item
}
BreadCrumbs.Parents.Reverse(); // reverse order of parents to get in correct order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment