I'm trying to modify my site's razor template to add breadcrumbs. I tried using this snippet - http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/breadcrumb - but that doesn't work with umbraco 6 (maybe the objects are called something different in the new core). Much appreciate any info pointing me in the right direction.
AFAIU you need to use either Model.Content or CurrentPage in MVC, both gives you the cached content, the difference is Model.Content is typed content, which gives you intellisense and works better with lambdas. Updated wiki:
Is it just me or isn't the breadcrumbs displayed in wrong order with that scripts? Instead of Home > Category > Sub category, I get Sub category > Category > Home. That's how they're displayed in the HTML. I could of course switch them around with float right or something, but shouldn't there be a way of getting them in the right order to start with?
...which is good because I didn't want the home page, but the order still wrong.
Btw, I'm using Umbraco 7. Theoretically that shouldn't change, because only the back-end has been updated.
razor syntax for breadcrumb in umbraco 6
I'm trying to modify my site's razor template to add breadcrumbs. I tried using this snippet - http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/breadcrumb - but that doesn't work with umbraco 6 (maybe the objects are called something different in the new core). Much appreciate any info pointing me in the right direction.
Hi Steve,
AFAIU you need to use either Model.Content or CurrentPage in MVC, both gives you the cached content, the difference is Model.Content is typed content, which gives you intellisense and works better with lambdas. Updated wiki:
http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/breadcrumb
/Jonas
Thanks so much for the updated wiki entry! That did the trick
Is it just me or isn't the breadcrumbs displayed in wrong order with that scripts? Instead of Home > Category > Sub category, I get Sub category > Category > Home. That's how they're displayed in the HTML. I could of course switch them around with float right or something, but shouldn't there be a way of getting them in the right order to start with?
Ok, it's just the "home" node that's misplaced, so I handled that one seperately and added .Where("level > 1") at the end of the select. Fixed it.
can you please update the wiki Daniel? Is this what you did ?
I now get
[no home page] > Parent > Grand-Parent > Page
...which is good because I didn't want the home page, but the order still wrong. Btw, I'm using Umbraco 7. Theoretically that shouldn't change, because only the back-end has been updated.
In v7 just use standard:
@foreach (var page in CurrentPage.Ancestors().OrderBy("Level")) {- @page.Name
}
- @CurrentPage.Name
is working on a reply...