Magento 2 – How to Override Adminhtml Template

adminhtmlmagento2template

I would like to overide the following admin template src/vendor/magento/module-sales/view/adminhtml/templates/order/view/history.phtml

This is what I made

module.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Cpy_Sales" setup_version="0.1.0">
        <sequence>
            <module name="Magento_Sales" />
        </sequence>
    </module>
</config>

Cpy/Sales/view/adminhtml/layout/sales_order_view.xml

Already have one extend there for the items, this one seems to be fine

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="order_items">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Cpy_Sales::order/view/items.phtml</argument>
            </action>
        </referenceBlock>
        <referenceBlock name='order_history'>
            <arguments>
                <argument name='template' xsi:type='string'>Cpy_Sales::order/view/history.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

Then my custom template is in : src/app/code/Cpy/Sales/view/adminhtml/templates/order/view/history.phtml
This template is basically the same but add an automatic "checked" attribute to the input history[is_customer_notified] so there is nothing very magical in there.

Best Answer

try replacing

<referenceBlock name='order_history'>
    <arguments>
       <argument name='template' xsi:type='string'>Cpy_Sales::order/view/history.phtml</argument>
   </arguments>
</referenceBlock>

with

<referenceBlock name='order_history'>
    <action method="setTemplate">
        <argument name='template' xsi:type='string'>Cpy_Sales::order/view/history.phtml</argument>
     </action>
</referenceBlock>
Related Topic