Copied to clipboard

Flag this post as spam?

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


  • Lungelo Keswa 16 posts 97 karma points
    Nov 24, 2022 @ 14:42
    Lungelo Keswa
    0

    hi please help me out I'm trying to add bread crumbs on my Umbraco 10 website but i'm getting an error

    can some one please help me

    @{

          var selection =     CurrentPage.Ancestors();
    
    
      if (selection.Any())
       {
          foreach (var page in selection.OrderBy("Level"))
         {
            <a class="bread-link bread-home" href="@page.Url()">@page.Name</a> <span> > </span>
              }
              <span>@CurrentPage.Name</span>
            }
        }
    
  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 24, 2022 @ 14:50
    Huw Reddick
    0

    what error are you getting?

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 24, 2022 @ 15:00
    Huw Reddick
    0

    I'm going to take a guess that your error relates to using page as your variable as I believe it is a reserved name (I had similar issues :) )

    This is my breadrumb code

    @{
        var CurrentPage = UmbracoContext.PublishedRequest.PublishedContent;
    
    }
    <ul class="forum-breadcrumb">
    
    @if (CurrentPage.Ancestors().Any())
    {
    
        foreach (var bpage in CurrentPage.Ancestors().OrderBy(x => x.Level))
        {
            if (!bpage.IsDocumentType("forumAuthHolder"))
            {
                <li class="d-none d-sm-block"><a href="@bpage.Url()">@bpage.Name</a>&nbsp;|&nbsp;</li>
            }
    
        }
    
        @* Display the current page as the last item in the list *@
        <li class="active d-none d-sm-block">@CurrentPage.Name</li>
    }
    
    </ul>
    
  • Lungelo Keswa 16 posts 97 karma points
    Nov 24, 2022 @ 15:32
    Lungelo Keswa
    0

    hi thanks man i'm getting an error now but the code I copied from your comment doesn't display anything on my page. Hmmmmmmmmmmmm maybe I'm adding it in the wrong place. Can you please walk me through on how you setted it up on your CMS

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 24, 2022 @ 16:23
    Huw Reddick
    100

    if you copied it exactly then it won't work as it has some code specific to my Forum templates, so you need to change this

    foreach (var bpage in CurrentPage.Ancestors().OrderBy(x => x.Level))
    {
        if (!bpage.IsDocumentType("forumAuthHolder"))
        {
            <li class="d-none d-sm-block"><a href="@bpage.Url()">@bpage.Name</a>&nbsp;|&nbsp;</li>
        }
    
    }
    

    To this

    foreach (var bpage in CurrentPage.Ancestors().OrderBy(x => x.Level))
    {
                    <li class="d-none d-sm-block"><a href="@bpage.Url()">@bpage.Name</a>&nbsp;|&nbsp;</li>
    
    }
    

    In my master template I just include it using

    @await Html.PartialAsync("_Breadcrumb")
    
  • Lungelo Keswa 16 posts 97 karma points
    Nov 25, 2022 @ 15:40
    Lungelo Keswa
    0

    sorry for the late reply man thank you so much for the code it worked.

  • Mike Allen 4 posts 74 karma points
    Nov 27, 2023 @ 21:46
    Mike Allen
    0

    Isn't this built into Unbraco or is there a module available ? When I used to use WP we just used the yoast plugin.

  • Huw Reddick 1736 posts 6076 karma points MVP c-trib
    Nov 28, 2023 @ 06:40
    Huw Reddick
    0

    No it isn't built in.

Please Sign in or register to post replies

Write your reply to:

Draft