0

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.

5

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').

  • That is absolutely brilliant. XML doesn't exactly put you in a creative mood for problem solving. Thank you. – LM_Fielding Jun 10 '16 at 9:29
  • 1
    No problem. Happy it was useful! – chicgeek Jun 10 '16 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>
  • As per the issue linked to in my example, this does not work. – chicgeek Feb 14 '17 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 – Arun Karnawat Mar 9 '18 at 11:30
  • it does not work in Magento2.2.4 – Zeeshan Khuwaja Aug 17 '18 at 4:18
  • This worked in Magento 2.3.0. I removed the RSS link for a specific category. – Garry Dec 28 '18 at 16:34
  • This should be the accepted answer as of 2.3.x. – Mark Shust Jul 9 at 19:48
0

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, privacy policy and cookie policy

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