BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs 2.1.1

dotnet add package BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs --version 2.1.1                
NuGet\Install-Package BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs -Version 2.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs" Version="2.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs --version 2.1.1                
#r "nuget: BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs, 2.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs as a Cake Addin
#addin nuget:?package=BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs&version=2.1.1

// Install BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs as a Cake Tool
#tool nuget:?package=BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs&version=2.1.1                

Xperience Breadcrumbs Component NuGet Version

This package provides a Mvc ViewComponent implementation, and accompanying services, for rendering Breadcrumbs based on Content Tree Routing.

Usage

  • Install the package into your Xperience Mvc project:
dotnet add package BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs

OR

<PackageReference Include="BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs" Version="x.x.x" />
  • Configure services in Startup.cs:
using BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs;
using Kentico.Web.Mvc;
using Microsoft.Extensions.DependencyInjection;

// ...

public void ConfigureServices( IServiceCollection services )
{
    services.AddMvc();
    services.AddKentico();

    // ...

    services.AddXperienceBreadcrumbsComponent();
}
  • Invoke the component within a Razor View:
@using BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs

@* ... *@

@await Component.InvokeAsync( nameof( XperienceBreadcrumbs ) )

@* OR *@

@( await Component.InvokeAsync<XperienceBreadcrumbs>( ) )

@* ... *@

Styling

This package does not provide any styling for breadcrumbs, consumers are required to implement their own styles. The Default.cshtml rendered DOM is intended to provide a semantic and extensible structure for easy styling:

div.breadcrumbs-container
    nav.breadcrumbs
        ol
            li.breadcrumb-item
            ...

Extensibility

Override Views

As described in the Razor Class Library documentation, Views created in the host Web Project take precedence over that of Views referenced in a Razor Class Library. This package provides the following Views that can be overridden to customize the rendering of breadcrumbs:

  • Views\Shared\Components\XperienceBreadcrumbs\_BreadcrumbItem.cshtml

Override this View to customize how individual BreadcrumbItems are rendered within the Default view.

  • Views\Shared\Components\XperienceBreadcrumbs\Default.cshtml

Override this View to completely override/customize how breadcrumbs are rendered.

Customize BreadcrumbItem Retrieval

The BreadcrumbsRetriever, the default IBreadcrumbsRetriever implementation, provides various virtual methods that allow customization of BreadcrumbItem retrieval and mapping. This can be done by inheriting from BreadcrumbsRetriever, and overriding the registration in the IServiceCollection:

CustomBreadcrumbsRetriever.cs

using BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs.Abstractions;
using BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs.Infrastructure;
using CMS.Base;
using CMS.DocumentEngine;
using Kentico.Content.Web.Mvc;
using Microsoft.Extensions.Options;

public class CustomBreadcrumbsRetriever : BreadcrumbsRetriever
{

    public CustomBreadcrumbsRetriever(
        IOptions<BreadcrumbRetrievalOptions> defaultOptions,
        IPageRetriever pageRetriever,
        IPageUrlRetriever pageUrlRetriever,
        ISiteService siteService
    ) : base( defaultOptions, pageRetriever, pageUrlRetriever, siteService )
    {
    }

    protected override BreadcrumbItem CreateBreadcrumbItem( TreeNode page )
    {
        var breadcrumb = base.CreateBreadcrumbItem( page );

        // Use a custom field for breadcrumb label
        breadcrumb.Label = node.GetStringValue(
            "CustomBreadcrumbLabel",
            breadcrumb.Label
        );

        return breadcrumb;
    }

}

Startup.cs

using BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs;
using Kentico.Web.Mvc;
using Microsoft.Extensions.DependencyInjection;

// ...

public void ConfigureServices( IServiceCollection services )
{
    services.AddMvc();
    services.AddKentico();

    // ...

    services.AddXperienceBreadcrumbsComponent();

    // replace ServiceDescriptor
    services.Replace(
        new ServiceDescriptor( typeof( IBreadcrumbsRetriever ), typeof( CustomBreadcrumbsRetriever ), ServiceLifetime.Transient )
    );
}

An IBreadcrumbsFilter contract and an abstract base class BreadcrumbsFilter are provided, which can be used to customize BreadcrumbItems prior to the XperienceBreadcrumbs ViewComponent invoking it's View. See the ExcludeLastBreadcrumbPathFilter for an example.

FAQ

  • Will this ViewComponent work if I'm not using Page Routing?

no.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on BizStream.Kentico.Xperience.AspNetCore.Components.Breadcrumbs:

Package Downloads
BizStream.Kentico.Xperience.AspNetCore.Components

A collection of ASP.NET Core Mvc ViewComponents that integrate with Xperience CMS.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.1 9,554 7/20/2021
2.1.1-beta.ff8773b 186 9/13/2021
2.1.1-beta.ec965f2 164 7/20/2021
2.1.1-beta.4aa17f0 159 9/29/2021
2.1.1-alpha.440ac6a 177 9/13/2021
2.1.0 1,714 7/19/2021
2.1.0-beta.b1e536c 166 7/16/2021
2.1.0-beta.8c6c3a1 265 7/16/2021
2.1.0-beta.8bfe389 212 7/16/2021
2.1.0-beta.45e07f5 203 7/16/2021
2.1.0-beta.41625fb 181 7/19/2021
2.1.0-beta.181bf86 247 7/16/2021
2.1.0-alpha.3a07ded 186 7/15/2021
2.0.1 1,825 7/14/2021