Web Analytics

Fill the form & Get Installation Support

    Let’s say I have to show category images to navigation menu.

    Magento doesn’t take a use of any kind of template to draw the whole menu, but a function which will retrieve all the categories & create li/ul tree.

    In Magento 2.1.X you can easily perform this task by rewriting the _getHtml() function from the class located at Magento\Theme\Block\Html\Topmenu. It’s kind of function which will call to itself again-n-again. We will make an observer which will add our programmed code in the navigation menu.

    1. Create your module

    Let’s start by creating one folder in app/code/Vendor/ModuleName.
    Here, ‘vendor’ is the namespace for your modules.

    Now the module registration:

    2. Rewrite this class Magento\Theme\Block\Html\TopMenu

    Create a file called di.xml to declare the rewriting of the class where the _getHtml() method is going to get called:

    After this you are allowed to create the class which will allow to rewrite the method. Now the following points:


    3. Make observer which will triggered by the event

    To perform it we have to create the events.xml configuration file and assign the class which will handle the event:




    Fill the below form if you have any Magento programming need.

      Recent Articles

      Author Info

      Hire B. Darji

      Get a Free Quote

        Let our Magento expert connect to discuss your requirement.

          We offer Magento
          certified developers.

          Our Magento clientele
          is 500+.

          We sign NDA for the
          security of your projects.

          We’ve performed 100+
          Magento migration projects.

          Free quotation
          on your project.

          Three months warranty on
          code developed by us.