Magento 2 Admin – How to Remove Block Using Custom Layout Update XML

adminlayoutmagento2xml

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.

Best Answer

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