2

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.

  • Please check my updated answer and let me know if its helpful for you or not – Rohan Hapani May 8 '18 at 10:35
1

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  
?>
  • thanks for your code , but i have created same type of code and added module on app/code directory but nothing showing on frontend – Jyoti Sharma May 8 '18 at 11:30
  • remove var and generated folder...and try it. – Rohan Hapani May 8 '18 at 11:48
  • ok what is ABC in this ? where i need to add this after create? in app/code folder ? – Jyoti Sharma May 8 '18 at 13:52
  • Its like app/code/ABC/Myblog – Rohan Hapani May 8 '18 at 15:02
  • Create ABC folder into app/code and then Create Myblog folder into app/code/ABC folder – Rohan Hapani May 8 '18 at 15:03
1

so finally I have created the module for add new tab. if anybody wants then download from here https://www.dropbox.com/s/23yt71gdh8xdbv9/Privacy.zip?dl=0 and activate module with the command

php bin/magento module:enable Privacy_Policy
0

You have to add your module to app/code.
After that run command php bin/magento setup:upgrade, php bin/magento setup:static-content:deploy -f and php bin/magento cache:flush from CLI.

  • i have run same command from putty , but still nothing showing on frontend – Jyoti Sharma May 8 '18 at 11:29
  • Try running php bin/magento setup:static-content:deploy -f and php bin/magento cache:flush as well – Anshu Mishra May 8 '18 at 11:51
  • after running these command my paid paid plugin start showing in admin but custom module still not showing, is this right location app/code for place module ? – Jyoti Sharma May 8 '18 at 14:06
  • Yes, the location is correct. Kindly share your code, may be there is some issue in the code. – Anshu Mishra May 9 '18 at 5:07
  • 1. as i already mentioned, i have follow magecomp.com/blog/… article and created module , i have not done any changes yet in article code. 2. i need to call this module anywhere ? or it should auto work after uploading ? – Jyoti Sharma May 9 '18 at 5:50
0

I often use a skeleton I get from here:

https://mage2gen.com/

Which takes out a lot of the grunt and setup work (be sure to verify whether everything in registration.php and such is accurate).

Magento modules have a Vendor name and a Module name. For example, my company is called Company, and I made a module to handle pricelists of our catalog, so the module is called Pricelist.

My module is placed so the file path looks like app/code/Company/Pricelist/...(module files)

After putting the files correctly, run (with the same folder that contains the app folder as the working directory) php bin/magento setup:upgrade. If you log in as admin, you'll be able to see your new module under Stores/Configuration/Advanced/Admin. It should show as enabled.

In the same folder, now run php bin/magento setup:di:compile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.