Templates in Breadcrumb

12 Apr 20226 minutes to read

The Breadcrumb component provides a way to customize the items using itemTemplate and the separators using separatorTemplate properties.

Item Template

In the following example, Shopping Cart details are used as breadcrumb Items and the items are customized by the chips component using itemTemplate.

<ejs-breadcrumb id="itemTemplate" cssClass="e-breadcrumb-chips" itemTemplate="#chipTemplate">
    <e-breadcrumb-items>
        <e-breadcrumb-item text="Cart"></e-breadcrumb-item>
        <e-breadcrumb-item text="Billing"></e-breadcrumb-item>
        <e-breadcrumb-item text="Shipping"></e-breadcrumb-item>
        <e-breadcrumb-item text="Payment"></e-breadcrumb-item>
    </e-breadcrumb-items>
</ejs-breadcrumb>

<script id="chipTemplate" type="text/x-template">
    <div class="e-lib e-chip-list e-control e-chip-set">
        <div class="e-chip" tabindex="0" role="option" aria-label="Apple" aria-selected="false">
            <span class="e-chip-text">${text}</span>
        </div>
    </div>
</script>
public ActionResult Index()
{
    return View();
}

Breadcrumb Sample

Separator Template

In the following example, the separators are customized with icons using separatorTemplate.

<ejs-breadcrumb id="itemTemplate" cssClass="e-breadcrumb-chips" separatorTemplate="@Html.Raw("<span class="e-icons e-bullet-arrow"></span>")">
    <e-breadcrumb-items>
        <e-breadcrumb-item text="Cart"></e-breadcrumb-item>
        <e-breadcrumb-item text="Billing"></e-breadcrumb-item>
        <e-breadcrumb-item text="Shipping"></e-breadcrumb-item>
        <e-breadcrumb-item text="Payment"></e-breadcrumb-item>
    </e-breadcrumb-items>
</ejs-breadcrumb>

style>
    .e-bullet-arrow::before {
        content: '\e253';
        font-size: 21px;
    }

    @@font-face {
        font-family: 'e-icons';
        src: url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMj1wSfkAAAEoAAAAVmNtYXDnHOdpAAABmAAAAD5nbHlmSRvkRAAAAegAAANoaGVhZB2Xb78AAADQAAAANmhoZWEIUQQHAAAArAAAACRobXR4GAAAAAAAAYAAAAAYbG9jYQSCAv4AAAHYAAAADm1heHABFwEfAAABCAAAACBuYW1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C4AMABlAC0AYgBjAG8AbgBzAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAHUAcwBpAG4AZwAgAFMAeQBuAGMAZgB1AHMAaQBvAG4AIABNAGUAdAByAG8AIABTAHQAdQBkAGkAbwB3AHcAdwAuAHMAeQBuAGMAZgB1AHMAaQBvAG4ALgBjAG8AbQAAAAACAAAAAAAAAAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYBAgEDAQQBBQEGAQcAE2RvY3VtZW50LXNldHRpbmctd2YOZm9sZGVyLW9wZW4tMDERY2hldnJvbi1yaWdodF8wMy0KY2hlY2stbWFyawhob3VzZS0wNAAAAAA=) format('truetype');
        font-weight: normal;
        font-style: normal;
    }

    .e-icons {
        font-family: 'e-icons' !important;
        font-size: 14px;
    }
</style>
public ActionResult Index()
{
    return View();
}

Breadcrumb Sample

Customize Specific Item Template

The specific breadcrumb item can be customizable using itemTemplate with conditional rendering. In the following example, added the span element only for the breadcrumb text in breadcrumb item.

<ejs-breadcrumb id="specific-item-template" cssClass="e-specific-item-template" itemTemplate="#specificItemTemplate">
    <e-breadcrumb-items>
        <e-breadcrumb-item text="Home" url="https://ej2.syncfusion.com/home/aspnetcore.html#platform"></e-breadcrumb-item>
        <e-breadcrumb-item text="Components" url="https://ej2.syncfusion.com/aspnetcore/Grid/GridOverview#/material"></e-breadcrumb-item>
        <e-breadcrumb-item text="Navigations" url="https://ej2.syncfusion.com/aspnetcore/Menu/DefaultFunctionalities#/material"></e-breadcrumb-item>
        <e-breadcrumb-item text="Breadcrumb" url="./Breadcrumb/DefaultFunctionalities"></e-breadcrumb-item>
    </e-breadcrumb-items>
</ejs-breadcrumb>
<script id="specificItemTemplate" type="text/x-template">
    <div>
        ${if(text=="Breadcrumb")}
        <span class="e-searchfor-text">
            <span style="margin-right: 5px">Search for:</span>
            <a class="e-breadcrumb-text" href="${url}" onclick="return false">${text}</a>
        </span>
        ${else}
        <a class="e-breadcrumb-text" href="${url}" onclick="return false">${text}</a>
        ${/if}
    </div>
</script>
<script>
    function beforeItemRenderHandler(args) {
        if (args.item.text !== 'Program Files') {
            args.item.disabled = true;
        }
    }

    function btnClick() {
        var breadcrumb, breadcrumbInst, breadcrumbs = document.querySelector('.content-wrapper').getElementsByClassName("e-breadcrumb");
        for (var i = 0; i < breadcrumbs.length; i++) {
            breadcrumb = breadcrumbs[i];
            breadcrumbInst = ej.base.getComponent(breadcrumb, 'breadcrumb');
            breadcrumbInst.activeItem = breadcrumbInst.items[breadcrumbInst.items.length - 1].text;
        }
    };
</script>
<style>
    .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>
public ActionResult Index()
{
    return View();
}

Output be like the below.

Breadcrumb Sample