It doesn't work because...
For example in the product view page this template is rendered: catalog/product/view.phtml.
This template contains at the top this line:
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
And $this->getMessagesBlock() is defined in Mage_Core_Block_Abstract and it looks like this:
public function getMessagesBlock()
{
if (is_null($this->_messagesBlock)) {
return $this->getLayout()->getMessagesBlock();
}
return $this->_messagesBlock;
}
This means that it calls: Mage_Core_Model_Layout::getMessagesBlock();
This last method is
public function getMessagesBlock()
{
$block = $this->getBlock('messages');
if ($block) {
return $block;
}
return $this->createBlock('core/messages', 'messages');
}
This means that if a block with the name 'messages' is not found in the layout is created and returned.
I see 2 possible solutions here:
- Edit all the template files and remove
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>. But I wouldn't take this road. It's to much time consuming and you might miss something.
- Override "magento style" the method:
Mage_Core_Block_Messages::getGroupedHtml() to return an empty string.
First I thought of overriding Mage_Core_Model_Layout::getMessagesBlock() to return nothing if the block is not in layout, but you will get errors when calling ->getGroupedHtml() on a non object.
but you can try overriding Mage_Core_Model_Layout::getMessagesBlock() to return a simple core/template block that does not have a method getGroupedHtml() method and will return null when called. (this would be the third solution.)