1

I Want to override this is Current theme path that i want to override. I have a file In

/public_html/app/design/frontend/Venustheme/fashion/Magento_Catalog/templates/product/view/gallery.phtml

but i want to override in my theme, Path Like :-

app/code/Vendor/Module/view/frontend/templates/gallery.phtml

here is my xml file :-preview_product_gallery.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.list.gallery">
                    <action method="setTemplate">
                        <argument name="template" xsi:type="string">Vendor_Module::gallery.phtml</argument>
                    </action>
                </referenceBlock>
            </referenceContainer>
        </body>
    </page>
  • You can't extend your theme file into your custom module, since magento 2 use fallback method so initially it will look up the file in your theme then into your custom module i.e., app/code... So in order to override your theme file create a child theme by parenting your current theme . In such a way you can extend I hope – Prathap Gunasekaran Mar 25 at 11:34
1

For example if you wants to overwrite the following file:

/var/www/html/magento2/app/design/frontend/<Vendor>/<Theme>/</Magento_Catalog/templates/product/list/items.phtml

in to your module, then copy above file in following location and updated as you wants:

/var/www/html/magento2/app/code/<Vendor>/<Module>/view/frontend/templates/product/list/items.phtml

and add following code(just for example) in your module xml file:

<referenceBlock name="product.info.upsell" template="Vendor_Module::product/list/items.phtml"/>

Let me know if this is works for you.

Thanks

  • Thank you @kamlesh, but its not working. am trying different file path /public_html/app/design/frontend/Venustheme/fashion/Magento_Catalog/templates/product/view/gallery.phtml – Praveen Negimani Mar 25 at 13:43
  • Ok, this is your theme path. Now, may I know your module path? – Kamlesh Yaduwanshi Mar 25 at 14:14
  • I think your module path to overwrite this file should be /public_html/app/design/frontend/<vendor>/<module>/view/frontend/templates/product/view/gallery.phtml – Kamlesh Yaduwanshi Mar 25 at 14:16
  • thanks @kamleshyes, my module path is same as above.. – Praveen Negimani Mar 26 at 4:24
  • still it not affecting – Praveen Negimani Mar 26 at 5:35
0

If you two module one is Vendor_Module for layout and Retailinsights_Preview for template file. then change code as belows in your preview_product_gallery.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.list.gallery">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Retailinsights_Preview::gallery.phtml</argument>
            </action>
        </referenceBlock>
     </referenceContainer>
</body>

  • sorry for vendor/module mismatch i edited question, please checkout – Praveen Negimani Mar 25 at 11:43
  • Please let me know your preview_product_gallery.xml file path in module ? – Mohit chauhan Mar 25 at 11:44
  • Thank you for response. /public_html/app/code/vendor/module/view/frontend/layout – Praveen Negimani Mar 25 at 11:46
0

You can try this code .

<?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.list.gallery">
                <action method="setTemplate">
                    <argument name="template" xsi:type="string">Retailinsights_Preview::gallery.phtml</argument>
                </action>
            </referenceBlock>
        </referenceContainer>
    </body>
</page>
-1

You can't overwrite a theme file with a module.

The best and cleanest way to handle this is creating you own theme that extends the one you are currently using and then overwriting the template.

This seems like it's a bit overkill at the beginning, but it has the benefit of your parent-theme to be updateable.

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.