Add Custom Tab On Customer Account Section In Magento 2

0
210
views
Add Custom Tab On Customer Account Section In Magento 2
Advertisement

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

<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

<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

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

<?php 
// Add Some Code Here
?>

I Hope this will help you. and in case if this solution is not working for you and you find another solution for that then I’ll request you all the guy’s please share to all.

Thank you ☺,
Mayank Zalavadia