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>
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!
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.
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")) {
...
}
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?
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:
It's not that neat to have too much logic in the Views, but this isn't too bad!
I have created a partial View and put it in there. I then call the partial from the master template.
Cool!
Then if you surround where you call the partial view with:
You should be all set! :)
EDIT: actually, save the bytes:
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.
Ahh, I see, so my assumption was that the pages were below the Home Page! Sorry!
Then you could do:
Thanks Daniel.
is working on a reply...