I recently got to a situation where I needed to add a new frontend template for some module and after some action show the error or success message. Not the first time though
. Interesting thing was even if I added this code in the PHTML file.
|
1
2
3
|
<span id="more-238"></span> |
It did not work. Yes, after adding this block it had worked before. In my case, the probable case might be that I had called the module’s template from CMS page. In other case it should work. So, I looked for work around and the following did the trick.
|
1
2
3
4
5
6
7
|
// Getting Messages from Session$messages=Mage::getSingleton("customer/session")->getMessages();// Creating Block Mage_Core_Block_Messages// Setting Message// echoing the Message's HTMLecho $this->getLayout()->createBlock("core/messages")->setMessages($messages)->getGroupedHtml(); |
The Error/Success or Notice messages are set on session. So what I did was take those message/s from the session and create a new block, same as what $this->getMessagesBlock() might have called, and set those message to the created block and echoed its HTML.
Clever? or not?
