Add Custom Tab On Customer Account Section In Magento 2

Posted on 22 July, 2016

Follow the steps listed below to add custom tab on customer account section on frontend in Magento 2. 

Add below files into your custom extension.

Ex:- Namespace:- Emipro Modulename : Myblog 

1. Create customer_account.xml into Emipro/Myblog/view/frontend/layout

1
2
3
4
5
6
7
8
9
10
11
12
<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-myblog">
            <arguments>
               <argument name="path" xsi:type="string">myblog/customer/index</argument>
               <argument name="label" xsi:type="string"> My Blog</argument>
            </arguments>
         </block>
      </referenceBlock>
   </body>
</page>                          

2. Create myblog_customer_index.xml into Emipro/Myblog/view/frontend/layout 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<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 Blog</argument
            </action
     </referenceBlock
     <referenceContainer name="content"
        <block class="Magento\Framework\View\Element\Template" name="my_email" template="Emipro_Myblog::myblog.phtml"
        </block
    </referenceContainer
</body
</page>                 

3. Create Index.php into Emipro/Myblog/Controller/Customer 

1
2
3
4
5
6
7
8
9
10
11
12
<?php 
namespace Emipro\Myblog\Controller\Customer;  
class Index extends \Magento\Framework\App\Action\Action { 
  
 public function execute() { 
  
    $this->_view->loadLayout(); 
    $this->_view->renderLayout(); 
  
  
?>                      

4. Create myblog.phtml into Emipro/Myblog/view/frontend/templates 

1
2
3
<?php 
 // Add Some Code Here  
?>                              

If you have any questions on how to add custom tabs on customer account in Magento 2 leave a comment below or contact us.


Mayank Zalavadia , eCommerce Project Manager
Magento Technical Notes

Post Your Review

X

Your Review has been posted

0 Comment(s)