I need to create a new tab in customer my dashboard using magento 2 called mymail(inbox). Any email, admin send to customer id then store also in this tab based on Gmail Inbox. Anyone know how to do this?
1 Answer
Add below files into your custom module
Ex:-Namespace:- Mytest Modulename : Myemail;
Create customer_account.xml into Mytest/Myemail/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-myemail"> <arguments> <argument name="path" xsi:type="string">myemail/customer</argument> <argument name="label" xsi:type="string"> MyEmail</argument> </arguments> </block> </referenceBlock> </body> </page>
Create myemail_customer_index.xml into Mytest/Myemail/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">MyEmail</argument> </action> </referenceBlock> <referenceContainer name="content"> <block class="Magento\Framework\View\Element\Template" name="my_email" template="Mytest_Myemail::test.phtml"> </block> </referenceContainer> </body> </page>
Create Index.php into Mytest/Myemail/Controller/Customer
<?php namespace Mytest\Myemail\Controller\Customer; class Index extends \Magento\Framework\App\Action\Action { public function execute() { $this->_view->loadLayout(); $this->_view->renderLayout(); } }
Create test.phtml into Mytest/Myemail/view/frontend/templates
<?php // Add some code ?>
Put routes.xml into folder Mytest/Myemail/etc/frontend with the following inside:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="myemail" frontName="myemail"> <module name="Mytest_Myemail" /> </route> </router> </config>
-
You have to create also routes.xml otherwise your controller will be 404 error.:) Commented Apr 27, 2017 at 5:28
-
@user3913802, Can you please let me know how I can create the routes.xml file for same module? Commented May 15, 2017 at 11:06
-
Put
routes.xml
into folderMytest/Myemail/etc/frontend
with the following inside:<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="myemail" frontName="myemail"> <module name="Mytest_Myemail" /> </route> </router> </config>
Commented May 19, 2017 at 17:18