Magento – Magento 2 add custom tab to account dashboard

adminmagento2tabs

I want to add a custom tab on account dashboard in Magento2 and I have seen many tutorials for creating new module but not one showing exact location for placing that module.

Right now I have placed my custom module on this path app/code folder but it is not working.

I have followed this tutorial for creating a new module,

https://magecomp.com/blog/add-custom-tab-in-customer-account-section-magento-2/#comment-5094

Anyone can help to know the exact location for placing module.

Best Answer

Follow the steps listed below :

Add below files into your custom extension.

Ex:- => Namespace:- ABC => modulename : Myblog

=> Create customer_account.xml into ABC/Myblog/view/frontend/layout

<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>

=> Create myblog_customer_index.xml into ABC/Myblog/view/frontend/layout

<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="ABC_Myblog::myblog.phtml"> 
        </block> 
    </referenceContainer> 
</body> 
</page>

=> Create Index.php into ABC/Myblog/Controller/Customer

<?php 
namespace ABC\Myblog\Controller\Customer;  
class Index extends \Magento\Framework\App\Action\Action { 

 public function execute() { 

    $this->_view->loadLayout(); 
    $this->_view->renderLayout(); 
  } 

} 
?>

=> Create myblog.phtml into ABC/Myblog/view/frontend/templates

<?php 
 // Add Some Code Here  
?>
Related Topic