When you are creating your own Magento 2 extension, you often have to remove a block. This was very easy in Magento 1. In M2 it’s very easy as well, but it’s just done a bit differently. Below is what you could use in M1.
<remove ="block_id_here" />
In Magento 2, this doesn’t work. The team at Magento has completely changed the way you remove a block from the layout in M2, and we’ll show you how to do it. The remove method is now simply
<referenceBlock name="block_name" remove="true"/>
Practical Example:
<?xml version="1.0"?> <page layout="3column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="block_name" remove="true"/> </body> </page>
As you can see, you place it between the body tags in the page layout in the layout.xml file that you are editing. It’s as simple as that! This method of removing a block this way has a few advantages over the old way, as you can now do things that previously were impossible. All in all its easier for Magento developers as you’ll be less frustrated when programming in the layout!
The post Remove Block from Layout in Magento 2 appeared first on Coding Basics.