Newer versions of Magento are using _toHtml() instead getGroupedHtml() in the template files.

But Mage_Core_Block_Messages::_toHtml() always just returns $this->getGroupedHtml() - Also back in Magento CE 1.5.1

Can anyone point out why it got changed in newer versions? Thanks!

1 Answer 1

  1. _toHtml() method:

Every block that extends Mage_Core_Block_Template can override that method to produce html output. The explanation is in Mage_Core_Block_Abstract class (which is extended by the Mage_Core_Block_Template class).

final public function toHtml()
        if ($html === false) {
            $html = $this->_toHtml();
        $html = $this->_afterToHtml($html);
        return $html;


protected function _toHtml()
        return '';

As you can see, toHtml() is a final method and you can't override it. Instead you can override _toHtml() and your html will be added to output by the $this->_toHtml() call.

  1. getGroupedHtml() method:

It is defined in Mage_Core_Block_Messages and it provides messages in HTML format grouped by type.

public function getGroupedHtml()
        $types = array(
        $html = '';
        return $html;

As you pointed out, the Mage_Core_Block_Messages::_toHtml() method calls the getGroupedHtml() to render the messages html output.

To wrap up, the methods _toHtml() and getGroupedHtml() are intended to serve different purposes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.