I'm trying to set/ display a template file instead of the default messaging in Magento 1.9 using an Observer when the checkout loads but I cannot get the phtml file to show up and I don't know why??

Here is the event that I am observing:


Next in the Observer I would like to add a phtml file using layout update xml so I have them defined in my module folder:

    <reference name="content">
        <block type="core/template" name="global_messages" template="custom/module/template.phtml" />

In my Observer I call:


And I can see the handler is added but nothing is being show on the page. I'm trying to add this template file in the same area as the global_messages block would be.

Am I using the correct apporach?


1 Answer 1


The first thing i noticed in your code is that the block type is not core/messages for the 'global_messages' (reference is app/design/frontend/base/default/layout/page.xml where the 'global_messages' block is defined).

However, if you check the app/code/core/Mage/Core/Block/Messages.php class, you will see that this block doesn't use a template file, it is rendered by default and that the HTML is generated in the getGroupedHtml() method.

So basically, you can change the HTML by creating a rewrite for this class and overwriting the getGroupedHtml() method. Just be aware that this class is also used in the admin side so overwriting it will impact the admin messages as well.

LE: if you are not very keen on rewriting the class I suggest another approach which would impact only the frontend and you might be lucky for it to work from the first try: copy the layout/page.xml file in your own theme and replace the 'global_messages' line with a line referencing a custom block class which inherits the app/code/core/Mage/Core/Block/Messages.php and a custom template file, then in the template file specifically call and print the $this->getGroupedHtml() method result.


Use the same approach as described above with a custom block class, only don't overwrite the entire 'page.xml', instead, reference the 'root' block in a custom layout file, invoke the remove block action, then re-add the global messages but this time with your custom block type and template. Something like this:

        <reference name="root">
            <remove name="global_messages" />
            <block type="custom_module/custom_messages_block" name="global_messages" template="custom_module/page/global_messages.phtml"/>
  • Thanks for your comment. I am trying to avoid a rewrite hence using an Observer, I only need to set a template where a the global_messages should be. Commented Mar 1, 2021 at 16:12
  • I see. Check the update in my answer, maybe it helps. It's not using an observer, tho'.
    – Diana
    Commented Mar 1, 2021 at 16:26
  • Botean I see it. However, I need to set this template in an area where the global messages are shown but without rewriting the messages class. Commented Mar 1, 2021 at 18:40
  • Well, you aren't rewriting the messages class (as described in my later edit) :) you are replacing it :)
    – Diana
    Commented Mar 1, 2021 at 19:41

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.