Magento 2 – How to Overwrite a Template via Module

blocksfrontendmagento2template

I am creating a module and want to overwrite the template app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/edit/options.phtml.

Is this possible in a module (not a theme)

Unfortunately it does not seem super-easy to change the module name via layout XML, as this is set hard-coded in https://github.com/magento/magento2/blob/develop/app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Options.php#L21

Best Answer

Add layout folder of you module file [Vendor]/[ModuleName]/view/adminhtml/layout/catalog_product_options.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="admin.product.options">
        <arguments>
            <argument name="template" xsd:type="string">[Vendor]/[ModuleName]::product_options.phtml</argument>
        </arguments>
    </referenceBlock>
</layout>

Also need add to module xml this line, to load you layouts after catalog

<sequence>
        <module name="Magento_Catalog"/>
</sequence>
Related Topic