Search code examples
c#sitecoresitecore8

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?


Solution

  • 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