Messages block not using theme template
-
16-10-2019 - |
سؤال
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?
المحلول
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:
Mage_Core_Block_Messages::setMessagesFirstLevelTagName($tagName)
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!