Copied to clipboard

Flag this post as spam?

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


  • Steve Brown 125 posts 290 karma points
    May 21, 2013 @ 14:39
    Steve Brown
    0

    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.

  • Jonas Eriksson 930 posts 1825 karma points
    May 22, 2013 @ 09:44
    Jonas Eriksson
    100

    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

  • Steve Brown 125 posts 290 karma points
    May 22, 2013 @ 16:24
    Steve Brown
    0

    Thanks so much for the updated wiki entry! That did the trick

  • Daniel 44 posts 187 karma points
    Jan 16, 2014 @ 16:43
    Daniel
    0

    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?

  • Daniel 44 posts 187 karma points
    Jan 16, 2014 @ 16:57
    Daniel
    0

    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.  

  • nick brandwood 3 posts 23 karma points
    Jan 28, 2014 @ 17:34
    nick brandwood
    0

    can you please update the wiki Daniel? Is this what you did ?

    <ul>
    @foreach (var ancestor in Model.Content.Ancestors().Where(t => t.IsVisible()).Where("level > 1"))
    {
        <li><a href="@ancestor.Url">@ancestor.Name</a></li>
    }
    <li>@Model.Content.Name</li>
    </ul>
    

    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.

  • Renaldas 26 posts 56 karma points
    Feb 25, 2014 @ 15:59
    Renaldas
    0

    In v7 just use standard:

    @if (CurrentPage.Ancestors().Any())
                        {
      @foreach (var page in CurrentPage.Ancestors().OrderBy("Level")) {
    • @page.Name
    • }
    • @CurrentPage.Name
                        }
Please Sign in or register to post replies

Write your reply to:

Draft