How does an extension display info and warning messages in a theme-agnostic way?
-
13-12-2019 - |
Question
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.
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange