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

About Emipro

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. Our customers are companies of all sizes ranging from startups to large enterprises who realize that they need a professional internet solution to generate revenue streams, establish proper communication channels, to achieve desired goals and streamline business operations. [....] Read More

Our writings seems informative ?

Subscribe for our Magento Technical Notes and get more amazing stuff directly to your inbox!

Post Your Review

X

Your Review has been posted

1 Comment(s)

kamlesh

Posted on 23 June, 2017

it's helpful. thanks