Copied to clipboard

Flag this post as spam?

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


  • Ole Kristian Losvik 22 posts 73 karma points
    Oct 03, 2016 @ 08:33
    Ole Kristian Losvik
    1

    Idea: new category for sharing working code snippets

    It would be great to have a section ion the page or in the forum to share code snippets without making a package out of it. For example, I wrote this yesterday, it is very simple - however maybe someone else could use it as well.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @*
        This snippet makes a breadcrumb of parents using an html ordered list.
        It makes metadata available for search engines in the Microdata format.
        The CSS is customised for Bootstrap 4
    *@
    
    @if (CurrentPage.Ancestors().Any())
    {
        dynamic pageAncestors = CurrentPage.AncestorsOrSelf().OrderBy("Level");
        string cssClass = "breadcrumb-item";
    <div>
        <ol class="breadcrumb" itemscope itemtype="http://schema.org/BreadcrumbList">
    
            @foreach (var page in pageAncestors)
            {
                if (page.level == pageAncestors.Count()) { cssClass = "breadcrumb-item active"; }
                    <li class="@cssClass" itemprop="itemListElement" itemscope
                        itemtype="http://schema.org/ListItem">
                        <a itemscope itemtype="http://schema.org/Thing"
                           itemprop="item" href="@page.Url">
                            <span itemprop="name">@page.Name</span>
                        </a>
                        <meta itemprop="position" content="@page.Level" />
                    </li>
            }
        </ol>
    </div>
    }
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies