Keith
Keith

Reputation: 4137

A modified breadcrumb for Sitecore

I'm looking to do a type of breadcrumb for one page, and the folder is nested with its page. It looks something like this in Sitecore:

 home/
   main/
     sub/
       Folder1/
         Page1/
         Page2/
         Page3/
       Folder2/
         Page1/
         Page2/
         Page3/
       Folder3/
         Page1/
         Page2/
         Page3/

Each of the pages uses the same template. My HTML looks simple:

<div class="container">
     <div class="folder"></div>
     <div class="pageTitle"><sc:FieldRenderer FieldName="Title" runat="server" />
</div>

I'm looking to grab whatever the page the user is on in the "Title" div and then its corresponding parent folder in the folder div. How would I go about achieving this?

Upvotes: 1

Views: 632

Answers (3)

VINAY SINGH
VINAY SINGH

Reputation: 11

public void GetBreadcrumbs(Item ParentItem)
        {
            List<BredCrumbDetails> lstBreadCrumbs = new List<BredCrumbDetails>();
            string strcurrenttitle = ParentItem.Name;
            Item currentitem = ParentItem;
            int i = 0;
            while (currentitem != null)
            {
                var ItemTemplateid = currentitem.TemplateID.ToString();
                var FolderTemplateId = "{B87A00B1-E6DB-45AB-8B54-636FEC3A5234}";
                if (ItemTemplateid != FolderTemplateId)
                {
                    BredCrumbDetails bcDetails = new BredCrumbDetails();
                    if (i == 0)
                    {
                        bcDetails.BCPageLink = null;
                        bcDetails.Title = currentitem.Name;
                        bcDetails.IsVisible = true;
                        lstBreadCrumbs.Add(bcDetails);
                    }
                    else
                    {
                        bcDetails.BCPageLink = currentitem.Paths.FullPath;
                        bcDetails.Title = currentitem.Name;
                        bcDetails.IsVisible = true;
                        lstBreadCrumbs.Add(bcDetails);

                    }
                    i++;
                    if (currentitem.Name == ("Home"))
                    {

                        break;
                    }
                    currentitem = currentitem.Parent;
                }
                else
                {
                    i++;
                    currentitem = currentitem.Parent;
                }
            }

            lstBreadCrumbs.Reverse();
            rptCrumbs.DataSource = lstBreadCrumbs;
            rptCrumbs.DataBind();

        }

Upvotes: 0

Chris Auer
Chris Auer

Reputation: 1445

My solution only works with code behind or the parent item being in a data bounding control like a repeater. Not sure why the parent would ever be in a repeater. So code behind it is.

<div class="container">
   <div class="folder">
      <sc:Text ID="parent" runat="server" Field="Page Title" />
   </div>
   <div class="pageTitle">
      <sc:Text ID="current" runat="server" Field="Title"/>
</div>

code behind

parent.Item = Sitecore.Context.Item.Parent;

Upvotes: 1

Jan Bluemink
Jan Bluemink

Reputation: 3487

The current Item is Sitecore.Context.Item and with Parent you get the parent Item. There you can get a Field. or in this example display the Name. For The Title Field you can use Sitecore.Context.Item.Parent.Fields["Title"].Value

    <div class="container">
     <div class="folder"><%=Sitecore.Context.Item.Parent.Name %></div>
     <div class="pageTitle"><sc:FieldRenderer FieldName="Title" runat="server" />
   </div>

Your example and this example is in Webforms today it is more common to use MVC. See Starting With Sitecore MVC

Upvotes: 2

Related Questions