Removing product_list_toolbar in Magento with Layout Update XML - why it isn’t possible
I’ve spent hours trying to figure out why the below code doesn’t remove the product_list_toolbar. Thinking there is something I don’t understand. Reading different stackexchange Q&A (and similar stuff), there is nearly always a solution, but there has been few explanations to why it isn’t working.
<referenceBlock name="product_list_toolbar" remove="true" />
It turns out Magento2 (and 1) doesn’t care about above. If you disable above, Magento will initiate a new one. Gaah. Thanks to Alan Storm, I figured it out.
Below is an extract from Alan Storm’s excellent explanation of why this isn’t working.
#File: vendor/magento/module-catalog/Block/Product/ListProduct.php public function getToolbarBlock() { $blockName = $this->getToolbarBlockName(); if ($blockName) { $block = $this->getLayout()->getBlock($blockName); if ($block) { return $block; } } $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime())); return $block; }
We see that, if Magento can’t fetch toolbar block, it instantiates a new one via code.
#File: vendor/magento/module-catalog/Block/Product/ListProduct.php $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, uniqid(microtime()));
Should it really be like this? Unclear. But there is an issue raised.
Now, the question is instead, how should you get it removed? I may come back on that.















