1

I want to remove a block on specific CMS pages and categories that can be accessed via the admin - rather than trying to figure out handles that will cover all of the pages I want to modify.

I want to remove the sidebar block on the page, however it will only accept the <referenceContainer>... not <referenceBlock name="sidebar" remove="true"/>

Any ideas? I'm sure I have done this before.

0

3 Answers 3

7

Strangely, I encountered the same challenge this week. I assume that this reported issue matches your problem: https://github.com/magento/magento2/issues/2247

This is my solution and it is terrible, but it does the trick. Create a new container, move your block(s) into that container, remove the new container.

<container name="bin" htmlTag="div" />
<move element="block.to.remove" destination="bin" />
<referenceContainer name="bin" remove="true" />

I would definitely like to see this issue fixed - I believe it to be a bug though the M2 devs seem to have dismissed it ('works as intended').

2
  • That is absolutely brilliant. XML doesn't exactly put you in a creative mood for problem solving. Thank you. Commented Jun 10, 2016 at 9:29
  • 1
    No problem. Happy it was useful! Commented Jun 10, 2016 at 14:20
3

The correct way to do it is probably something along these lines...

<container name="body">
    <referenceBlock name="catalog.leftnav" remove="true" />
</container>
5
  • As per the issue linked to in my example, this does not work. Commented Feb 14, 2017 at 10:41
  • it was not working for me on 2.1.x, but is working now on 2.2.2, just clear the cache after editing Commented Mar 9, 2018 at 11:30
  • it does not work in Magento2.2.4 Commented Aug 17, 2018 at 4:18
  • This worked in Magento 2.3.0. I removed the RSS link for a specific category. Commented Dec 28, 2018 at 16:34
  • This should be the accepted answer as of 2.3.x. Commented Jul 9, 2019 at 19:48
1

It will accept the referenceBlock if you wrap it in a <body> tag. You also may need to use display="false" instead of remove="true". Try this:

<body>
  <referenceBlock name="sidebar" remove="true"/>
</body>

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.