11

I want to customize product details page, So it required to override some .phtml files in following locations.

So I want to know, how to override .phtml files in vendor\magento\module-catalog\view\frontend\templates\product or vendor\magento\module-theme\view

16

Sometimes we need to make modifications to existing templates. Instead of making changes directly to existing template files, we should override them in our own theme. Let us assume that we want to update the category listing page ( list.phtml ). To do so, create following directory structure:

app/design/frontend/Mycompany/Basic/Magento_Catalog/templates/product

Here I assume that our current theme is Basic. Now copy the list.phtml file into product directory from the following location:

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

Now you can make any modifications you want to your overridden file.

For detail please read this tutorial it's help you lot.

  • 2
    Hi, I just overrides the list.phtml file in the following path, \app\design\frontend\Magento\luma\Magento_Catalog\templates\product\list.phtml. But it hasn't worked. Can I know where I did wrong? – Vigna S Oct 5 '16 at 6:21
  • Same problem, no matter how many times i hit refresh the default one is loaded over my custom one. And YES i have the correct path before anyone asks, but I am using composer to install magento so the defaults are in different locations if that matters. – Dustin Poissant May 4 '18 at 15:35
  • I had to clear the html block cache and then this worked perfectly for me! (I clear cache like this blog.gardenhouse.io/2018/05/29/…) – paul Jun 13 '18 at 21:16
6

To override phtml, layout and web files to own custom theme

1) To Override template file:

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

Follow this path

app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/list.phtml

2) To Override layout file:

vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml

Follow this path

app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml

  • How to override/customize other module files like Observer, Controller etc? – Tahir Yasin Oct 2 '17 at 13:08
5

To Override pthml and layout files from

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

into

app/Mycompany/OverideCatalog/view/frontend/templates/product/list.phtml

Layout:

vendor/magento/module-catalog/view/frontend/layout/catalog_category_view.xml

into

app/Mycompany/OverideCatalog/view/frontend/layout/catalog_category_view.xml

<block class="Magento\Catalog\Block\Product\ListProduct" name="category.products.list" as="product_list" template="Mycompnay_OverideCatalog::product/list.phtml">
5

I am answering my own question,

I found out how to override the .phtml files in the locations mentioned in my question,

You have to put them in following locations to override the original files

app\design\frontend\<VENDOR_NAME>\<THEME_NAME>\Magento_Catalog\templates\product\view

And I believe the theory is same for overriding any other .phtml files in Magento 2

  • Could you please brief more...Like i have to copy my custom phtml file into the theme folder isit? like into app\design\frontend\<VENDOR_NAME>\luma\Magento_Catalog\ Should i have to create my Vendor folder and copy the core phtml file into it? If by doing so, no need of templates in view folder? – Sushivam Aug 18 '16 at 9:41
  • Hi, I am trying to override a phtml file for a widget, and I'm not sure the path I have used is correct. Is the Magento_Catalog part of your path specific to the module folder you are overriding? So, if I am overriding the vendor\magento\module-catalog-widget\view\frontend\templates\product\widget\content, would I replace Magento_Catalog in your instance with Magento_Catalog_Widget in my instance? Slightly confused as it isn't clear to me yet. – robgt May 11 '17 at 10:10
2

override templates(phtml) by custom theme

if you want to override vendor\magento\module-catalog\view\frontend\templates\product\some.phtml first you need to create your custom theme, please refer this link for how to create custom theme.

after that create phtml file in your custom theme to override default one

 app/design/frontend/vendor-name/theme-name/Magento_Catalog/templates/product/some.phtml

thats it finally clear the cache of magento as well as browser, then check your page, new phtml file only reflected.

same way you can do for all templates override.

good luck

  • Thanks, I just figured it out and answered the finding in my own questions, your answer is much similar to my findings. – nuwaus May 21 '16 at 14:03
2

Open folder : /vendor/magento/theme-frontend-luma/ and copy the module templates and layout files from the view folder.

Then create folders : /app/design/frontend/spacename/Theme/

Then create module folder and then create templates and layout folder.

Insert the templates and layout files from the module view folder.

protected by Community Sep 20 '18 at 22:10

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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