2

I need to override the widget template file /vendor/magento/module-catalog/view/frontend/templates/product/widget/new/content/new_grid.phtml but in xml file the phtml file was not mentioned at any where except on /etc folder.

<parameter name="template" xsi:type="select" required="true" visible="true">
    <label translate="true">Template</label>
    <options>
        <option name="default" value="product/widget/new/content/new_grid.phtml" selected="true">
            <label translate="true">New Products Grid Template</label>
        </option>
    </options>
</parameter>

How can I override the vendor-widget-phtml file new_grid.phtml to my custom module.

5

this way i get changes of phtml by my custom module

app/code/VendorName/ModuleName/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">

    <preference for="Magento\Catalog\Block\Product\Widget\NewWidget" type="MyModule\WidgetOverride\Block\Product\Widget\NewWidget" />

</config>

app/code/VendorName/ModuleName/Block/Product/Widget/NewWidget.php

<?php
namespace MyModule\WidgetOverride\Block\Product\Widget;

class NewWidget extends \Magento\Catalog\Block\Product\Widget\NewWidget
{
  protected function _construct()
    {
      parent::_construct();
      $this->setTemplate('VendorName_ModuleName::product/widget/content/new_grid.phtml');
    }
}

now add your phtml file this path app/code/VendorName/ModuleName/view/frontend/templates/product/widget/new/content/new_grid.phtml

frontend shows my changes on product page by override phtml file

enter image description here hope this help you :) Happy coding.

7
  • I have tried this but still the changes I'm doing in the phtml is not showing on frontend.
    – Siva
    Oct 22 '20 at 6:55
  • Thanks. I will check and update you
    – Siva
    Oct 22 '20 at 11:33
  • I did try your code but still the update is not showing in frontend.
    – Siva
    Oct 23 '20 at 13:22
  • yes I have ran all the commands
    – Siva
    Oct 23 '20 at 16:11
  • 1
    Hi @Siva sorry for late response, plz check updated answer, last time we override wrong block file :) this override done new_grid.phtml. Oct 26 '20 at 15:32

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.