3

We want to remove Magento's default main navigation using xml file but don't want to use remove, because ifconfig not working with remove.

We want to remove main navigation only when our custom module is disabled.

We have tried below codes but it's not working.

// CODE 1
<referenceContainer name="store.menu">
    <action method="unsetChild" ifconfig="rootmegamenu_option/general/enable">
        <argument name="alias" xsi:type="string">catalog.topnav</argument>
    </action>
</referenceContainer>

// CODE 2
<referenceContainer name="store.menu">
     <action method="unsetChild"><child>catalog.topnav</child></action>
</referenceContainer>

// CODE 3
<referenceContainer name="store.menu">
     <action method="unsetChild" ><name>catalog.topnav</name></action>
</referenceContainer>

Help will be appreciated.

1

This is a very late response, but I just managed to do this by adding the following to my default.xml file:

<referenceBlock name="navigation.sections" display="false" />

I found out the element name by looking around in /vendor/magento/module-theme/view/frontend/layout/default.xml.

0
  1. Refer this link to check module staus
  2. Follow the below instructions to remove the item programmatically

    if ($this->moduleManager->isOutputEnabled('Vendor_Module')) {
        $layout = $this->getLayout();
        $block = $layout->getBlock('Block Name'); // block name
        $layout->unsetElement('Block Name');
    } else {
        //the module output is disabled
    }
    

I hope it helps!

  • Thank you Bilal Usean but we want to do this from xml file only. Is there any way to do this from XML file? – Vish Dec 25 '17 at 7:27

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.