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 7 posts 87 karma points
    4 days ago
    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 829 posts 2817 karma points
    4 days ago
    Huw Reddick
    0

    what error are you getting?

  • Huw Reddick 829 posts 2817 karma points
    4 days ago
    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 7 posts 87 karma points
    4 days ago
    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 829 posts 2817 karma points
    4 days ago
    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 7 posts 87 karma points
    3 days ago
    Lungelo Keswa
    0

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

Please Sign in or register to post replies

Write your reply to:

Draft