Orchardcore breadcrumbs

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore breadcrumbs is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for Orchard Core 4.0 breadcrumbs on admin screens and front-end views. Covers the breadcrumb and breadcrumb-item tag helpers, the required IHtmlContent title and safe HtmlContentString wrapping, ancestor links with routes, URLs, permissions and link-enabled, IBreadcrumbProvider and BreadcrumbC

How to use this skill

Skill file

Orchard Core Breadcrumbs

Orchard Core 4.0 renders admin page titles as a named trail with an explicit current-page title, e.g. _Dashboard › Manage Content › Edit Article_. The Breadcrumb and BreadcrumbItem shapes live in the always-enabled OrchardCore.Navigation module; the tag helpers live in OrchardCore.Navigation.Core. No feature needs to be enabled and inline authoring needs no provider registration.

Mental Model

Adding a Breadcrumb to a View

Import the tag helpers once in the module's Views/_ViewImports.cshtml (reference the OrchardCore.Navigation.Core package or project):

@addTagHelper *, OrchardCore.Navigation.Core

Put the helper in the Title zone, replacing the old <h1> and any @RenderTitleSegments(...) call for the same title:

<zone Name="Title">
    <breadcrumb name="RecordsEdit" title="@T["Edit {0}", Model.Record.Name]">
        <breadcrumb-item id="Records" action="Index" controller="Record" area="My.Module"
                         permission="@MyPermissions.ManageRecords.Name">@T["Records"]</breadcrumb-item>
    </breadcrumb>
</zone>

A page with no ancestors (or whose ancestors come only from providers) still declares both attributes:

<zone Name="Title">
    <breadcrumb name="Records" title="@T["Records"]" />
</zone>

Rendering it in the Title zone keeps the Display titles in the top bar admin setting working; TheAdmin's own Breadcrumb.cshtml moves the trail into the Breadcrumbs zone above the title. A trail that should not carry the page title goes in the Breadcrumbs zone with heading="" (and page-title="false" when the page registers its browser title itself).

Naming

`<breadcrumb>` Attributes

| Attribute | Type | Behavior |

|---|---|---|

| name | string | Required stable trail name. |

| title | Microsoft.AspNetCore.Html.IHtmlContent | Required and non-null, including LocalizedHtmlString. HtmlString.Empty suppresses heading and browser-title text but still leaves the current node in a visible trail. |

| heading | string | Heading tag rendered below the trail. Defaults to h1 on admin requests and to none on the front end. heading="" renders none. |

| page-title | bool | Registers the title as a <title> segment. Defaults to true everywhere. |

| display-type | string | Defaults to DetailAdmin on admin requests and Detail elsewhere; becomes an alternate of every shape the trail renders. |

Title Values

Pass the Razor localizer result directly. Wrap anything that is not already IHtmlContent with OrchardCore.DisplayManagement.Html.HtmlContentString, which encodes untrusted strings when written:

| Value in the view | Title expression |

|---|---|

| HTML-localized label | title="@T["Edit {0}", record.Name]" |

| Plain model string | title="@(new HtmlContentString(Model.DisplayText ?? string.Empty))" |

| LocalizedString (IStringLocalizer) | title="@(new HtmlContentString(localizedTitle.Value ?? string.Empty))" |

| DataLocalizedString (IDataLocalizer) | title="@(new HtmlContentString(dataTitle.Value ?? string.Empty))" |

| Intentionally empty | title="@Microsoft.AspNetCore.Html.HtmlString.Empty" |

Add @using OrchardCore.DisplayManagement.Html for the short form. Never extract T[...].Value or use Html.Raw as a conversion.

The helper renders the title once with WriteTo(writer, HtmlEncoder.Default), HTML-decodes it once, then safely encodes that plain text for the heading, the current node, and the browser title. Output is always text-only: IHtmlContent does not allow markup in titles, and a literal &amp; wrapped with HtmlContentString stays literal.

`<breadcrumb-item>` Attributes

The child content is the ancestor text, e.g. @T["Records"] (HTML-decoded after Razor evaluates it, then re-encoded on output).

| Attribute | Type | Behavior |

|---|---|---|

| id | string | Stable node ID for shape alternates (not an HTML id). |

| action, controller, area | string | MVC route target; prefer these over hand-built URLs. |

| route-* | string | Extra route values, e.g. route-id="@record.Id". |

| route-values | IDictionary<string, string> | Extra route values as a dictionary (not an anonymous object or RouteValueDictionary). |

| url | string | Direct link; ignored when action is set. |

| permission | string | Permission name stored as BreadcrumbItem.PermissionName; unknown names are ignored. |

| resource | object | Resource the permission is evaluated against. |

| link-enabled | bool | Defaults to true; false renders the ancestor as plain text. |

There is no position attribute: BreadcrumbItem has no Position and does not implement IPositioned. Unauthorized ancestors, ancestors with link-enabled="false", and ancestors without a target stay visible as plain text; permissions control links, not node visibility. Named permissions are resolved only when finalizing visible ancestor links after providers run. Link checks are not endpoint security: keep authorization on the target action.

Nested Editors

Link back through the real parent entity, read from the view model or loaded with an existing service injected into Razor (not a breadcrumb-specific service):

@inject OrchardCore.ContentManagement.IContentManager ContentManager
@{
    var parent = await ContentManager.GetAsync(Model.ParentContentItemId);
}

<zone Name="Title">
    <breadcrumb name="RecordsEdit" title="@T["Edit {0}", Model.Record.Name]">
        <breadcrumb-item id="Records" action="Index" controller="Record" area="My.Module">@T["Records"]</breadcrumb-item>
        <breadcrumb-item id="Parent" action="Edit" controller="Record" area="My.Module"
                         route-id="@parent.ContentItemId"
                         permission="@MyPermissions.ManageRecords.Name"
                         resource="@parent">@T["Edit {0}", parent.DisplayText]</breadcrumb-item>
    </breadcrumb>
</zone>

Postprocessing with `IBreadcrumbProvider`

Use a provider for shared or cross-module ancestor changes; keep screen-specific nodes in the owning view.

public interface IBreadcrumbProvider
{
    ValueTask BuildBreadcrumbAsync(BreadcrumbContext context);
}

BreadcrumbContext (namespace OrchardCore.Navigation) exposes read-only properties; its constructor is BreadcrumbContext(string name, string title, List<BreadcrumbItem> items, ViewContext viewContext, bool showTrail).

| Property | Type | Use |

|---|---|---|

| Name | string | Literal trail name; filter on it explicitly. |

| Title | string | Normalized plain-text title. Providers cannot change the current node. |

| Items | List<BreadcrumbItem> | Shared mutable ancestor list: add, insert, remove, reorder, or edit. The current node is not in it. |

| ViewContext | ViewContext | Request context, e.g. AdminAttribute.IsApplied(context.ViewContext.HttpContext). |

| ShowTrail | bool | Always true in helper-created contexts; hidden trails never invoke providers. |

using Microsoft.Extensions.Localization;
using OrchardCore.Admin;
using OrchardCore.Navigation;

public sealed class RecordsBreadcrumbProvider : IBreadcrumbProvider
{
    private readonly IStringLocalizer S;

    public RecordsBreadcrumbProvider(IStringLocalizer<RecordsBreadcrumbProvider> localizer)
    {
        S = localizer;
    }

    public ValueTask BuildBreadcrumbAsync(BreadcrumbContext context)
    {
        if (!AdminAttribute.IsApplied(context.ViewContext.HttpContext) ||
            !context.Name.StartsWith("Records", StringComparison.Ordinal) ||
            context.Name == "Records" ||
            context.Items.Any(item => item.Id == "Records"))
        {
            return ValueTask.CompletedTask;
        }

        context.Items.Insert(0, new BreadcrumbItem
        {
            Id = "Records",
            Text = S["Records"].Value,
            RouteValues = new() { ["area"] = "My.Module", ["controller"] = "Record", ["action"] = "Index" },
            PermissionName = "ManageRecords",
        });

        return ValueTask.CompletedTask;
    }
}
services.AddBreadcrumbProvider<RecordsBreadcrumbProvider>();

Dashboard Ancestor

Enabling OrchardCore.AdminDashboard registers OrchardCore.AdminDashboard.Services.DashboardBreadcrumbProvider. On admin requests it inserts a localized Dashboard ancestor (ID Dashboard) at index 0, unless context.Name == "Dashboard" or an ancestor already has that ID. Its Url is "~/" + AdminOptions.AdminUrlPrefix and its Permissions list holds the static OrchardCore.AdminDashboard.Permissions.AccessAdminDashboard permission, so a denied user sees it as plain text. It never changes front-end trails or the title, and later providers can move it. The dashboard page itself uses <breadcrumb name="Dashboard" title="@T["Dashboard"]" />.

Hiding Admin Breadcrumbs

Show breadcrumb under Settings → Admin (AdminSettings.ShowBreadcrumb, default true) hides admin trails only:

{
  "steps": [
    {
      "name": "settings",
      "AdminSettings": {
        "ShowBreadcrumb": false
      }
    }
  ]
}

When hidden, the helper never evaluates its child content, never resolves or runs providers (Dashboard included), creates no BreadcrumbContext or items, generates no URLs, checks no permissions, and renders no shapes. It renders only the title, directly in a heading with the oc-breadcrumb-title class, and registers the browser title according to heading and page-title; with heading="" and page-title="false" it still requires a non-null title but does not even render it. Breadcrumb template overrides therefore do not apply to the hidden state. Attribute expressions (T[...], HtmlContentString wrappers) and Razor code or model lookups outside the child content still run.

All visibility decisions belong to the tag helper. Views must not read AdminSettings.ShowBreadcrumb or guard lookups, ancestor declarations, or the helper on it. Front-end trails ignore the setting.

Front-End Use

The same helpers work in a front-end theme with display type Detail and no heading by default:

@using OrchardCore.DisplayManagement.Html

<breadcrumb name="ProductDetails" title="@(new HtmlContentString(Model.Product.Name ?? string.Empty))" page-title="false">
    <breadcrumb-item id="Catalog" action="Index" controller="Catalog" area="My.Module">@T["Catalog"]</breadcrumb-item>
</breadcrumb>

A visible front-end trail always evaluates its children and providers, even with no heading and page-title="false". Providers see front-end trails too unless they filter on the request, and the Dashboard provider leaves them unchanged.

Theming

| Shape | Alternates (least to most specific) |

|---|---|

| Breadcrumb | Breadcrumb__[Name], Breadcrumb_[DisplayType], Breadcrumb_[DisplayType]__[Name], e.g. Breadcrumb-ContentsEdit.cshtml, Breadcrumb.DetailAdmin.cshtml, Breadcrumb-ContentsEdit.DetailAdmin.cshtml |

| BreadcrumbItem | BreadcrumbItem__[Name], BreadcrumbItem__[Id], BreadcrumbItem__[Name]__[Id], then the same three with the display type, e.g. BreadcrumbItem-ContentsEdit-Title.DetailAdmin.cshtml |

See references/breadcrumbs-examples.md for the full alternate tables, a title-above-trail override, and the low-level shape API.

Gotchas

Upgrading from 3.x

Related Skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.