Magento 2 Template – Overriding the Catalog Widget

magento2template

I am trying to override the the catalog widget template found in this directory:

/vendor/magento/module-catalog-widget/view/frontend/templates/product/widget/content/grid.phtml

I copied the grid.phtml file to:

mytheme/Magento_Catalog_Widget/templates/product/widget/content/grid.phtml

But this hasn't worked and the widget I have put on my page is still pulling in the default template. Any ideas? I am pretty sure I am using the right directory as all other template files I have overridden have worked fine. Tried flushing the cache and no joy.

I noticed the code the wysiwyg generates for the widget on the page references a template file. I presume this is still overridden?

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" products_count="4" template="product/widget/content/grid.phtml" conditions_encoded="a:2:[i:1;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Combine`;s:10:`aggregator`;s:3:`all`;s:5:`value`;s:1:`1`;s:9:`new_child`;s:0:``;]s:4:`1--1`;a:4:[s:4:`type`;s:50:`Magento|CatalogWidget|Model|Rule|Condition|Product`;s:9:`attribute`;s:12:`category_ids`;s:8:`operator`;s:2:`==`;s:5:`value`;s:2:`32`;]]"}}

Best Answer

You have to just rename your theme module directory like Magento_CatalogWidget.

New file path for your theme: mytheme/Magento_CatalogWidget/templates/product/widget/content/grid.phtml

When core module name with - you have to remove that and make the next character Uppercase.

Eg.: if you want to override core module module-catalog-inventory then your path would be Magento_CatalogInventory.

Related Topic