6

Not looking to display form validation errors, but more global messages like "Hurry quick -- offer ends in 4 hours" or "Currently there are 3 users online".

The question is not about how to generate the messages, but how to best present them in a way that will work nicely in any (or at least most) themes.

1 Answer 1

4

You can use the Magento notification system. It should work anywhere anytime.

Notice

Mage::getSingleton(‘core/session’)->addNotice(‘Notice message’);

Success

Mage::getSingleton(‘core/session’)->addSuccess(‘Success message’); 

Error

Mage::getSingleton(‘core/session’)->addError(‘Error message’); 

Mage::getSingleton(‘adminhtml/session’)->addWarning(‘Warning message’); 

(Admin only)

If this is not what you are looking for but the block in charge of displaying these messages, you need the message block.

3
  • Thanks for this. Problem with the above is that the message sometimes isn't visible until the next click. Any way around that?
    – fris
    Commented Jul 7, 2015 at 8:27
  • Where are you setting the messages? If you set the message in a PHTML it will be shown on the next refresh, you should set it in a controller.
    – mbalparda
    Commented Jul 7, 2015 at 13:27
  • Not always possible to set all messages in the controller. I output them as they come up, e.g. when an error condition arises (like an Exception).
    – fris
    Commented Jul 9, 2015 at 8:28

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.