Templates in Blazor Breadcrumb
14 Aug 20265 minutes to read
Blazor has templated components that accept one or more UI segments and render them as part of the component. The Blazor Breadcrumb is a templated component that lets you customize parts of its UI through template parameters. Use templates to render custom components or content based on your own logic.
The available template options in the Blazor Breadcrumb are:
- ItemTemplate - Customizes each Breadcrumb item.
- SeparatorTemplate - Customizes the separator between items.
Template context
The templates used by Breadcrumb are of type RenderFragment and they will be passed with parameters. You can access the parameters passed to the templates using implicit parameter named context. You can also change this implicit parameter name using Context attribute.
Item template
In the following example, shopping cart details are used as Breadcrumb items and each item is rendered as a SfChip using the ItemTemplate tag directive. Access the current item through the context parameter.
@using Syncfusion.Blazor.Navigations
@using Syncfusion.Blazor.Buttons
<SfBreadcrumb class="e-breadcrumb-chips">
<BreadcrumbItems>
<BreadcrumbItem Text="Cart"></BreadcrumbItem>
<BreadcrumbItem Text="Billing"></BreadcrumbItem>
<BreadcrumbItem Text="Shipping"></BreadcrumbItem>
<BreadcrumbItem Text="Payment"></BreadcrumbItem>
</BreadcrumbItems>
<BreadcrumbTemplates>
<ItemTemplate>
<SfChip>
<ChipItems>
<ChipItem Text="@context.Text" Enabled="true"></ChipItem>
</ChipItems>
</SfChip>
</ItemTemplate>
</BreadcrumbTemplates>
</SfBreadcrumb>NOTE
The
ItemTemplatereplaces the default item rendering. If you want users to be able to click the item, you must render an anchor or button yourself and bind theUrlfromcontext.Url. To useSfChip, add theSyncfusion.Blazor.ButtonsNuGet package.
Separator template
In the following example, the separators are customized with an icon using the SeparatorTemplate tag directive. Access the previous and next items through the context.CurrentItem and context.NextItem properties.
@using Syncfusion.Blazor.Navigations
<SfBreadcrumb>
<BreadcrumbItems>
<BreadcrumbItem Text="Cart"></BreadcrumbItem>
<BreadcrumbItem Text="Billing"></BreadcrumbItem>
<BreadcrumbItem Text="Shipping"></BreadcrumbItem>
<BreadcrumbItem Text="Payment"></BreadcrumbItem>
</BreadcrumbItems>
<BreadcrumbTemplates>
<SeparatorTemplate>
<span class="e-icons e-bullet-arrow"></span>
</SeparatorTemplate>
</BreadcrumbTemplates>
</SfBreadcrumb>Customize a specific item
Customize a single Breadcrumb item by providing custom content as the BreadcrumbItem child content. The default Text rendering is replaced by your custom content. In the following example, a <span> element with a label and link is rendered only on the last item.
@using Syncfusion.Blazor.Navigations
<SfBreadcrumb EnableNavigation="false" class="e-specific-item-template" ActiveItem="@SpecificTemplateActiveItem">
<BreadcrumbItems>
<BreadcrumbItem Text="Home" Url="https://blazor.syncfusion.com/demos/" />
<BreadcrumbItem Text="Components" Url="https://blazor.syncfusion.com/demos/datagrid/overview" />
<BreadcrumbItem Text="Navigations" Url="https://blazor.syncfusion.com/demos/menu-bar/default-functionalities" />
<BreadcrumbItem>
<span class="e-searchfor-text">
<span style="margin-right: 5px">Search for:</span>
<a class="e-breadcrumb-text" href="./breadcrumb/default-functionalities" aria-label="Breadcrumb demo link" onclick="return false">Breadcrumb</a>
</span>
</BreadcrumbItem>
</BreadcrumbItems>
</SfBreadcrumb>
@code{
private string SpecificTemplateActiveItem = "";
}
<style>
@@font-face {
font-family: 'e-bicons';
src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1wSfkAAAEoAAAAVmNtYXDnHOdpAAABmAAAAD5nbHlmSRvkRAAAAegAAANoaGVhZB2Xb78AAADQAAAANmhoZWEIUQQHAAAArAAAACRobXR4GAAAAAAAAYAAAAAYbG9jYQSCAv4AAAHYAAAADm1heHABFwEfAAABCAAAACBuYW1lXj/4/wAABVAAAAIlcG9zdE4LDloAAAd4AAAAegABAAAEAAAAAFwEAAAAAAAD9AABAAAAAAAAAAAAAAAAAAAABgABAAAAAQAA6q1k4F8PPPUACwQAAAAAAN1ClWcAAAAA3UKVZwAAAAAD9AP0AAAACAACAAAAAAAAAAEAAAAGARMABwAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQQAAZAABQAAAokCzAAAAI8CiQLMAAAB6wAyAQgAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZ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mctd2YOZm9sZGVyLW9wZW4tMDERY2hldnJvbi1yaWdodF8wMy0KY2hlY2stbWFyawhob3VzZS0wNAAAAAA=) format('truetype');
font-weight: normal;
font-style: normal;
}
.e-searchfor-text {
display: flex;
align-items: center;
font-size: 14px;
font-weight: normal;
}
.e-searchfor-text .e-breadcrumb-text {
padding-left: 0;
}
.e-bigger .e-searchfor-text {
font-size: 16px
}
.fabric .e-searchfor-text,
.fabric-dark .e-searchfor-text,
.highcontrast .e-searchfor-text {
font-size: 18px;
}
.e-bigger.fabric .e-searchfor-text,
.e-bigger.fabric-dark .e-searchfor-text,
.e-bigger.highcontrast .e-searchfor-text {
font-size: 21px;
}
.e-specific-item-template .e-breadcrumb-item:last-child a:hover {
text-decoration: underline;
}
</style>NOTE
When you supply child content for a
BreadcrumbItem, theTextandUrlproperties are ignored. To make the link clickable, use Blazor’s@onclickwithNavigationManager.NavigateTo(context.Url)instead of the legacyonclickHTML attribute, which requires interactive render mode.