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.

3 Answers 3

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.

1

If you want to remove the navigation, without the navigation section. You could also implement it by putting the following line in any .xml file preferably the default.xml to apply it everywhere.

<referenceBlock name="catalog.topnav" remove="true"/>

When the entire navigation section has to be removed the following line can be used.

<referenceBlock name="navigation.sections" remove="true"/>
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!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.