How to add custom tab in Customer Account Sidebar Magento 2

First of all, you will need to create customer_account.xml file here in your custom module..

app/code/SK/CustomerAccountTab/view/frontend/layout/customer_account.xml

Content of the File

<?xml version=”1.0″?>

<!–

/**

 *

 * @package  SKCustomerAccountTab

 * @author  Kishan Savaliya <kishansavaliyakb@gmail.com>

 */

–>

<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=”MagentoFrameworkViewElementHtmlLinkCurrent” name=”customer-account-navigation-new-tab”>

        <arguments>

          <argument name=”path” xsi:type=”string”>sk_route/front/index</argument>

          <argument name=”label” xsi:type=”string”>Custom tab (SK)</argument>

        </arguments>

      </block>

    </referenceBlock>

  </body>

</page>

Create your action layout file.

File Name and PAth: app/code/SK/CustomerAccountTab/view/frontend/layout/sk_route_front_index.xml

<?xml version=”1.0″?>

<!–

/**

 *

 * @package  SKCustomerAccountTab

 * @author  Kishan Savaliya <kishansavaliyakb@gmail.com>

 */

–>

<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn: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”>Custom Tab (SK)</argument> 

      </action> 

    </referenceBlock> 

    <referenceContainer name=”content”> 

      <block class=”MagentoFrameworkViewElementTemplate” name=”custom_tab_sk” template=”SK_CustomerAccountTab::tab_content.phtml” />

    </referenceContainer> 

  </body>

</page>

Create controller action file.

app/code/SK/CustomerAccountTab/Controller/Front/Index.php

<?php

/**

 *

 * @package  SKCustomerAccountTab

 * @author  Kishan Savaliya <kishansavaliyakb@gmail.com>

 */

namespace SKCustomerAccountTabControllerFront;

class Index extends MagentoFrameworkAppActionAction

{

  public function execute()

  {

    $this->_view->loadLayout(); 

    $this->_view->renderLayout();

  } 

}

Create the template File for the page

app/code/SK/CustomerAccountTab/view/frontend/templates/tab_content.phtml

Leave a comment

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