Question

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?

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top