Add breadcrumbs in Magento2

I am going to explain here a way to add a breadcrumb in the default Magento Contact Us Page as an example

1) Create a layout file
I have a theme module Decryptweb_Project, so creating a layout file inside it

app/design/frontend/Decryptweb/Project/Magento_Contact/layout/contact_index_index.xml

2) Reference the existing breadcrumbs block

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> 
    <body>
    <referenceBlock name="breadcrumbs">
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string" translate="true">Home</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string" translate="true">Home</item>
                    <item name="label" xsi:type="string" translate="true">Home</item>
                    <item name="link" xsi:type="string">{{baseUrl}}</item>
                </argument>
            </action>
            <action method="addCrumb">
                <argument name="crumbName" xsi:type="string" translate="true">Contact Us</argument>
                <argument name="crumbInfo" xsi:type="array">
                    <item name="title" xsi:type="string" translate="true">Contact Us</item>
                    <item name="label" xsi:type="string" translate="true">Contact Us</item>
                </argument>
            </action>
        </referenceBlock>       
    </body>
</page>

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top