12

I am trying to change the phtml file for the messages block. I found in the base theme template/core/messages.phtml and copied that over to my theme and made the changes. My changes didn't show so I tried modifying the source in the base file and the changes still were not applied.

Where is this template file located or how can I overwrite it?

  • Hey kel did you figure this one out in the end? – jharrison.au Mar 15 '13 at 5:43
11

Unfortunately the core/messages.phtml file is not used for the messages you're speaking of. All the HTML is generated on the Block level in Mage_Core_Block_Messages.

The good news is you can control the tags used in the messages by calling these functions:

  1. Mage_Core_Block_Messages::setMessagesFirstLevelTagName($tagName)
  2. Mage_Core_Block_Messages::setMessagesSecondLevelTagName($tagName)

An example of implementing this would be to modify your layout/page.xml file by finding the lines that read:

<block type="core/messages" name="global_messages" as="global_messages"/>
<block type="core/messages" name="messages" as="messages"/>

And changing them to something like:

        <block type="core/messages" name="global_messages" as="global_messages">
            <action method="setMessagesFirstLevelTagName"><tagName>div</tagName></action>
            <action method="setMessagesSecondLevelTagName"><tagName>span</tagName></action>
        </block>
        <block type="core/messages" name="messages" as="messages">
            <action method="setMessagesFirstLevelTagName"><tagName>div</tagName></action>
            <action method="setMessagesSecondLevelTagName"><tagName>span</tagName></action>
        </block>

And if you need even more control then you could override the block in your own module and customise the getHtml() and getGroupedHtml() methods.

Happy styling!

  • I'm constantly amazed at what can be accomplished via layout xml actions – philwinkle Mar 14 '13 at 4:59
  • Yeah they're great - you can call any block method through layout XML just the same as you would in a *.phtml file with $this->doSomething() or $this->setSomeData('foobar'). – jharrison.au Mar 14 '13 at 5:05
  • How do you add css classes? I would like to apply twitter bootstrap styles – Sven Apr 17 '13 at 7:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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