1

I have created a Magento 2 module which has some customization for the category pages.

I would like to remove catalog.leftnav when the category is using the "2 columns with right bar" layout. Is there anyway I can do this in my modules Layout files?

So far I've tried adding <referenceBlock name="catalog.leftnav" remove="true" /> to <my_module_dir>/view/frontend/page_layout/2columns-right.xml but this did nothing.

Then I tried adding <referenceBlock name="catalog.leftnav" remove="true" /> to <my_module_dir>/view/frontend/layout/catalog_category_view.xml but this removed it from everywhere, even pages with 3 column layout.

UPDATE

After reading through the docs on this, I have now also tried creating the following file app/design/frontend/Holy/mytheme/Magento_LayeredNavigation/page_layout/2columns-right.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
    <body>
        <!--<move element="catalog.leftnav" destination="sidebar.main" before="-"/>-->
        <!--<update handle="2columns-right"/>-->
        <referenceBlock name="catalog.leftnav" remove="true" />
    </body>
</layout>

But this did not work either.

0

catalog.leftnav is a container so you need to use:

<referenceContainer name="catalog.leftnav" remove="true" />

When you are choosing the layout for the category, you can also remove the leftnav by updating the Layout Update XML settings for the category with this. It is right below the page layout option.

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.