Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I am using magento 1.8. I have custom theme. I am unable to get newsletter error/success messages when customer submit their email-id for subscription.

I have done many changes to get and print messages. But it won't work.

I am getting messages by below code

$messages = Mage::getSingleton('core/session')->getMessages(true);
    echo "<pre>"; var_dump($messages);

object(Mage_Core_Model_Message_Collection)#281 (2) {
  ["_messages":protected]=>
  array(0) {
  }
  ["_lastAddedMessage":protected]=>
  object(Mage_Core_Model_Message_Error)#120 (6) {
    ["_type":protected]=>
    string(5) "error"
    ["_code":protected]=>
    string(102) "Il y a eu un problème lors de l'inscription : This email address is already assigned to another user."
    ["_class":protected]=>
    string(0) ""
    ["_method":protected]=>
    string(0) ""
    ["_identifier":protected]=>
    NULL
    ["_isSticky":protected]=>
    bool(false)
  }
}

But I am unable to print it. I have tried below code.

   foreach($messages->getItems() as $message) {
        echo $message->getText();
}

Even I am not getting any thing in forloop. Help me,, Thanks in advance:)

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You can print the messages in a template like this:

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>

But there is a catch.
For example the newsletter subscription message is added to Mage::getSingleton('core/session').
So in order to see te core/session messages you need to add this in the controller that renders the template:

$this->_initLayoutMessages('core/session');

after calling

$this->loadLayout();
share|improve this answer
    
Wow, good to know, thanks! I always thought it is a core bug, that only core/session is rendered! :D –  Fabian Blechschmidt Aug 21 at 8:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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