2

I need to override

/vendor/magento/module-catalog/view/frontend/templates/product/view/gallery.phtml.

For this, in app/code/namespace/Customtab/view/frontend/layout/catalog_product_view.xml

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>

    <referenceContainer name="content">
        <referenceBlock name="product.info.addtocart">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">namespace_Customtab::product/view/gallery.phtml</argument>
            </action>
        </referenceBlock>
     </referenceContainer>
</body>

paste the custom phtml file in

app/code/namespace/Customtab/view/frontend/templates/product/view/gallery.phtml.

But it didn't works.Please help me to find a solution.

3

Use this:

<?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="product.info.media.image">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Namespace_Customtab::product/view/gallery.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  • It works fine :) – Rita Jose May 30 '17 at 7:32
1

Customizing the core Magento 2 functionality is a bad coding practice. The solution is to override a phtml file using a custom module in Magento 2.

Methods to Override a phtml file using a custom module in Magento 2:

  1. with plugin
  2. with XML

Learn the implementation of both the methods at https://meetanshi.com/blog/override-phtml-file-using-custom-module-in-magento-2/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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