2

I want to override product view page and add my custom code over that.

So please help me on how can I override template of product view page.

Thank you.

1
  • Have many methods to custom template of product view page. May you show detail which you want to custom on the page. – MrTo-Kane Apr 16 '16 at 16:40
6

@Dmync In order to accomplish this the basic answer is "it depends." The first question that would need to be answered is "What do you want to override?" This question is too broad.

If you're trying to override some template(s) that are in place by default for product view then you can need to track down the templates you want to override. You can do so by either of the following:

  1. Follow directions here: enable template hints
  2. Go to vendor/magento/module-catalog/view/frontend/layout/catalog_product_view.xml and track down all the template files that are explicitly assigned here, as well as all other templates included via <update> layout instruction update docs

Once you know which templates you want to update, then you can follow the general ideas within this page to create the correct module structure. Basically if you're creating a module to perform these actions then you'll need a structure like:

app/code/<Vendor>/<module>/view/frontend/Magento_Catalog/templates and then you'd continue to refer to the structure of Magento_Catalog for it's folder hierarchy...and you'd add that into your module...so

If you're wanting to override vendor/magento/module-catalog/view/frontend/templates/product/view/form.phtml then you'd create app/code/<Vendor>/<Module>/view/frontend/Magento_Catalog/templates/product/view/form.phtml. Then you could do your customizations there..again, refer to the templates customization doc I linked.

If you're trying to do this via a theme. Using the above example....you'd create app/design/frontend/<Vendor>/<theme>/Magento_Catalog/product/view/form.phtml and perform whatever customizations you'd like in that template.

So which ever way you go about it, either creating a custom module or a custom design theme, and if you're simply modifying the template content, you're going to need to recreate the target module (in this case Magento_Catalog) in your own custom module/theme (using the correct directory hierarchies...as it's slightly different between module/theme).

If you're interested in modifying css then look here for info on overriding css.

If you need to modify some of the page's layout xml files to rearrange elements, remove elements, add elements, etc...look here to get started.

As you can see, there's a lot that can take place in simply "Overriding product view page."

1
1

If you want only override template file of product view page, You need to set template inside your custom theme file from vendor/module-catalog,

Magento2/app/design/frontend/{{Packagename}}/{{themename}}/Magento_Catalog/templates/

After insert template in above path and you can change your custom code related to view file.

Thanks.

1
  • how to override from admin side? I need to override the product view of admin – jafar pinjar Nov 8 '18 at 6:00

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.