Magento2 Tips & Tricks

How to Remove Block Programmatically in Magento 2

How to Remove Block Programmatically in Magento 2 December 28, 2017Leave a comment

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

In this tutorial, you will go through how to easily remove block programmatically in magento 2. This trick will be very useful and handy when you want to remove block programmatically with magento 2.

You can simply use unsetElement() method to remove block. as like

$layout = $this->getLayout();
$block = $layout->getBlock('catalog.topnav'); // block name
$layout->unsetElement('catalog.topnav');

I hope you like this post, Please feel free to comment below, your suggestion and problems!

How to Remove Block Programmatically in Magento 2
5 (100%) 1 vote

(Visited 5 times, 1 visits today)

Hello World, I am Chandra Kumar from New Delhi, India. I am professionally developer, programmer and blogger. I am the founder of WebShouters.com.

Leave a Reply

Your email address will not be published. Required fields are marked *