8

I'm developing a custom module in magento 2. I need to change the file located in Magento/Sales/view/Adminhtml/Templates/Items/Column/name.phtml.

How can I override file in custom extension?

1 Answer 1

19

Try following way:

Vendor/Module/view/adminhtml/layout/sales_order_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="column_name">
            <action method="setTemplate">
                <argument name="template" translate="true" xsi:type="string">Vendor_Module::order/items/column/name.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Copy original file into following location:

Vendor/Module/view/adminhtml/templates/order/items/column/name.phtml

Clear cache.

4
  • 2
    Beware that using action tag is no longer recommended, you should use <referenceBlock name="column_name" template="Vendor_Module::order/items/column/name.phtml"/> Feb 2, 2017 at 7:33
  • Don't worry, look here github.com/magento/magento2/issues/3356
    – Sohel Rana
    Feb 2, 2017 at 7:55
  • What if the file does not have a layout and it is set in code. Like magento/module-payment/view/adminhtml/templates/info/substitution.phtml
    – tread
    May 11, 2017 at 14:04
  • @StevieG you can overwrite any template by replacing your own theme, or overwrite Block class and set $_template variable or this answer.
    – Sohel Rana
    May 11, 2017 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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