2

I want to magento default menu in my other phtml file. how to call it?

I didn't found any code for menu please help me.

Thanks

3

If you want Top Menu in CMS Page then you can use below code in CMS Page.

{{block class="Magento\Theme\Block\Html\Topmenu" template="Magento_Theme::html/topmenu.phtml"}}

But as you mention you want in another Phtml then you can try to put belove code in Phtml.

echo $this->getLayout()->createBlock("Magento\Theme\Block\Html\Topmenu")->setTemplate("Magento_Theme::html/topmenu.phtml")->toHtml();

Hope this will help!

0

Default Menu render by class Magento\Theme\Block\Html\Topmenu In default.xml layout module-theme

<block class="Magento\Framework\View\Element\Template" name="store.menu" group="navigation-sections" template="Magento_Theme::html/container.phtml">
     <arguments>
         <argument name="title" translate="true" xsi:type="string">Menu</argument>
      </arguments>
      <block class="Magento\Theme\Block\Html\Topmenu" name="catalog.topnav" template="html/topmenu.phtml" ttl="3600" before="-"/>
</block>

You can change template to new template you want. All content of menu render by class Topmenu. You can extend this class if you need customize menu

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.