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
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIf 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!
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