Most of the time, as a Magento 2 extension developer, we have to dip our hands into both backend and frontend. In this blog, I will present to you how to make a Menu in customer’s My Account menu on frontend. I will use my example code in one of our module: GiftRegistry.

This picture denotes our expected outcome:

add menu on magento n2

InstallSchema

We will create a database for the table, our table’s data will be from this database.

Make a file named magenest_registry_event in Setup/InstallSchema.php

Model

Next up, create our table’s model: Model/Event.php

Model/ResourceModel/Event.php

Model/ResourceModel/Event/Collection.php

 View/Frontend

 This is where frontend components are handled frontend/layout/customer_account.xml.

This is the file which add a Tab named My Gift Registry in the My Account menu of a customer. The data will be passed onto giftregistry/customer/registry controller for handling. Make sure the path is correct. 

After that, we need to create one more layout file which will create a block and its template frontend/layout/giftregistry_customer_registry.xml

 Add frontend/templates/customer/gifregistry/list.phtml

This is the template file which add the table components and display it. You can customize it to suit your need.

Controlller

Better late than never, lets create our controller file in Controller/Customer/Registry

This will put List Gift Registry as the title of the page.

Block

This is one crucial part, make a file named Block/Customer/Registry/ListGift.php

This is the place where data will be received from database and handled then passed onto the template file to display.

Shares 0