0

I have overwritten the _beforeToHtml() method in the class Magento\CatalogWidget\Block\Product\ProductsList. After doing this, I received the following error:

Invalid template file: 'product/widget/content/grid.phtml' in module: 'My_Module'

When I move the product/widget/content/grid.phtml template from my theme to my module, the error message dissapears. When I add the Magento_CatalogWidget:: prefix to the template in widgets.xml, the error doesn't go away.

4
  • share the code what you have try. Commented Oct 9, 2018 at 14:09
  • What is the full path of your product/widget/content/grid.phtml ?
    – PЯINCƎ
    Commented Oct 9, 2018 at 21:22
  • @PRINCE My/Theme/Magento/Catalog/templates/product/widget/content/grid.phtml, but now I am forced to place it in My/Module/view/frontend/templates/product/widget/content/grid.phtml Commented Oct 10, 2018 at 7:06
  • So your need is to place it in module or theme ?
    – PЯINCƎ
    Commented Oct 10, 2018 at 8:01

1 Answer 1

1

If you want to rewrite that template in your module, you have to do it via xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance dc" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <referenceBlock name="{block.name}">
        <action method="setTemplate">
            <argument name="template" xsi:type="string">Magento_CatalogWidget::product/widget/content/grid.phtml</argument>
        </action>
    </referenceBlock>
</page>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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