Overriding a Magento Adminhtml template file

2019-09-07 07:53发布

问题:

I'm attempting to override a particular block on a page, in this case it's the Sales_Order_View_History template. The problem I'm seeing is that this block is already being overridden.

The custom module that is overriding this block is using an observer that basically does: when History.php is to be loaded, load Historytwo.php instead. History.php is also being used on two separate pages in the back end. I must only override it on one page. This has gotten me absolutely lost. I do believe that the module I'm wanting to override the template of is only overriding the one I'd like to override.

What I have seen as the generally accepted format for overriding blocks is:

<adminhtml>
    <rewrite>
       <sales_order_view_companyhistory>
       Namespace_Package_Blocks_Adminhtml_Sales_Order_View_Companyhistory_Content</

The above code is giving me a broken layout that is stopping the rendering of most of the blocks/templates.

回答1:

If the other module uses an observer on the "adminhtml_block_html_before" event, have you tried to rewrite their observer model to make it do what you want ?
And in the same time, you could also add your own observer on the same event, that would do the same thing, but only when the other module is not enabled (eg, by checking with Mage::helper('core')->isModuleEnabled()), so that it would work in all cases.



回答2:

These two configuration snippets will rewrite two separate classnames.

sales is mapped in Mage/Sales/etc/config.xml:

global/blocks/sales/class>Mage_Sales_Block

adminhtml is mapped in Mage/Adminhtml/etc/config.xml:

global/blocks/adminhtml/class>Mage_Adminhtml_Block