How to overwrite a template via module in Magento2
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>
- Create corresponding layout file in your module:
[Vendor]/[ModuleName]/view/adminhtml/layout/catalog_product_options.xml
- Set your custom template configuration
<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"> <action method="setTemplate"> <argument name="template" xsi:type="string">[Vendor]_[ModuleName]::product_options.phtml</argument> </action> </referenceBlock> </layout>
NOTE: it is very important to use <action method="setTemplate">
instead of <arguments>
. <arguments>
will only work if the block does not have another template specified on the xml declaration. In any other case, you need <action method="setTemplate">
to override the existing template. It is better to use <action method="setTemplate">
because it always works.