I'm trying to change product options templates :
<block class="Magento\Catalog\Block\Product\View\Options" name="product.info.options" as="product_options" template="product/view/options.phtml">
<block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="product/view/options/type/default.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Text" as="text" template="product/view/options/type/text.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\File" as="file" template="product/view/options/type/file.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Date" as="date" template="product/view/options/type/date.phtml"/>
</block>
In my module, I try several methods:
<referenceBlock name="text" template="Vendor_Module::path/to/newfile.phtml" />
--
<referenceBlock name="text">
<action method="setTemplate">
<argument name="template" xsi:type="string">Vendor_Module::path/to/newfile.phtml</argument>
</action>
</referenceBlock>
--
<referenceBlock name="text">
<arguments>
<argument name="template" xsi:type="string">Vendor_Module::path/to/newfile.phtml</argument>
</arguments>
</referenceBlock>
This one is really weird
To check, i try with name = "copyright", and it works...
How can I do it with product options templates ?
Note : The changes that will be made in the templates are not for appearance.
Excuse my english
1 Answer 1
Try this.
In your extension your_extension/view/frontend/layout/catalog_product_view.xml
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="product.info.options" remove="true" />
<referenceBlock name="product.info.options.wrapper">
<block class="Magento\Catalog\Block\Product\View\Options" name="yourcustomname.product.info.options" as="yourcustomname.packaging_product_options" template="product/view/options.phtml">
<block class="Magento\Catalog\Block\Product\View\Options\Type\DefaultType" as="default" template="product/view/options/type/default.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Text" as="text" template="Your_Extension::product/view/options/type/text.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\File" as="file" template="product/view/options/type/file.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Select" as="select" template="product/view/options/type/select.phtml"/>
<block class="Magento\Catalog\Block\Product\View\Options\Type\Date" as="date" template="product/view/options/type/date.phtml"/>
</block>
</referenceBlock>
</body>
And copy
vendor/magento/module-catalog/view/frontend/templates/product/view/options/type/text.phtml
to
your_extension/view/frontend/templates/product/view/options/type/text.phtml
You make the modifications in the text.phtml of your extension.
This solution could cause problems if there is another extension that modifies the block product.info.options