Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rachel Reveley 4 posts 74 karma points
    Feb 04, 2016 @ 09:24
    Rachel Reveley
    0

    Breadcrumb snippet show breadcrumb in top level pages

    Hi,

    Just getting started with Umbraco by jumping in and moving our company site over from Django. I am trying to use the breadcrumb snippet included in Umbraco but want it to show on all pages including top level pages except for the home page.

    Is this possible?

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @*
    This snippet makes a breadcrumb of parents using an unordered html list.
    
    How it works:
    - It uses the Ancestors() method to get all parents and then generates links so the visitor can go back
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @*
    This snippet makes a breadcrumb of parents using an unordered html list.
    
    How it works:
    - It uses the Ancestors() method to get all parents and then generates links so the visitor can go back
    - Finally it outputs the name of the current page (without a link)
    *@
    <div class="breadcrumb-block">
    <section>
    @{ var selection = CurrentPage.Ancestors(); }
    
    @if (selection.Any())
    {
        <ul class="breadcrumbs">
            <li class="first">You are here:</li>
        @* For each page in the ancestors collection which have been ordered by Level (so we start with the highest top node first) *@
        @foreach (var item in selection.OrderBy("Level"))
        {
            <li><a href="@item.Url">@item.Name</a> <span class="divider">/</span></li>
        }
    
        @* Display the current page as the last item in the list *@
        <li class="active">@CurrentPage.Name</li>
    </ul>               
    }
    </section>
    

  • Daniel 60 posts 174 karma points
    Feb 04, 2016 @ 11:13
    Daniel
    0

    Which template are you inserting this macro on?

    You could probably insert it on your Master template (Master layout - inserted via a Partial to keep the logic in it's own partial view) and then do a check for something like:

    if (CurrentPage.Level != 1) { //depending on the level depth of your home page / if your home page isn't at the root of your Content tree, you'd want to change the level
         @Html.Partial("path-to-breadcrumb-partialview")
    }
    

    It's not that neat to have too much logic in the Views, but this isn't too bad!

  • Rachel Reveley 4 posts 74 karma points
    Feb 04, 2016 @ 11:26
    Rachel Reveley
    0

    I have created a partial View and put it in there. I then call the partial from the master template.

  • Daniel 60 posts 174 karma points
    Feb 04, 2016 @ 11:36
    Daniel
    0

    Cool!

    Then if you surround where you call the partial view with:

    if (CurrentPage.Level != 1) {
    ...
    }
    

    You should be all set! :)

    EDIT: actually, save the bytes:

    if (CurrentPage.Level > 1) {
    ...
    }
    
  • Rachel Reveley 4 posts 74 karma points
    Feb 04, 2016 @ 11:49
    Rachel Reveley
    0

    Would this not exclude the breadcrumb from top level pages? Or do you mean that my other pages should be one level down from the homepage?

    It has just occurred to me that I didn't explain that the breadcrumb doesn't currently show on About us, Contact us etc. It only appears on the test page.

    enter image description here

  • Daniel 60 posts 174 karma points
    Feb 04, 2016 @ 12:00
    Daniel
    1

    Ahh, I see, so my assumption was that the pages were below the Home Page! Sorry!

    Then you could do:

    //I'm guessing your Home Page document type has the alias "homePage" ? if not, check Settings and the doc type alias to find it
    @if (!CurrentPage.DocumentTypeAlias.Equals("homePage")) {
    ...
    }
    
  • Rachel Reveley 4 posts 74 karma points
    Feb 04, 2016 @ 13:16
    Rachel Reveley
    0

    Thanks Daniel.

Please Sign in or register to post replies

Write your reply to:

Draft