Add custom link to my account menu

First of all we will need to find out they responsible layout and block for the navigation menu. The layout is the customer_account.xml and the block is the customer_account_navigation.

STEP – 1

Simply create a customer_account.xml file under your theme directory /app/design/frontend/VENDOR/THEME/Magento_Customer/layout/ and add the following code.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Framework\View\Element\Html\Link\Current" name="customer-account-navigation-custom" before="customer-account-navigation-orders-link">
                <arguments>
                    <argument name="path" xsi:type="string">quote/customer/index</argument>
                    <argument name="label" xsi:type="string">My Quotes</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

after this create a route customer index

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_account"/>
    <body> <referenceBlock name="page.main.title">
        <action method="setPageTitle"> <argument translate="true" name="title" xsi:type="string">My Custom Tab</argument>
        </action>
    </referenceBlock>
        <referenceContainer name="content">
            <block class="Magento\Framework\View\Element\Template" name="my_tab" template="JJ_Quote::quote.phtml"> </block>
        </referenceContainer>
    </body>
</page>

Step – 2

createa index.php at app/code/VENDOR/MODULE/Controller/CUSTOMNAME

<?php
namespace JJ\Quote\Controller\Customer;
class Index extends \Magento\Framework\App\Action\Action {
    public function execute() {
        echo " ";
        $this->_view->loadLayout();
        $this->_view->renderLayout();

    }
}
?>

Step – 3

create a module

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="JJ_Quote" setup_version="1.0.1"></module>
</config>

Step – 4

Create a phtml in Vendor/Module/view/frontend/templates

<?php

?>
<span>Your Content</span>

Step -5

Clear cache and refresh page to see new custom link on my account section

Leave a comment

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