I am new to Magento 2 and theming and I'm having trouble overriding a particular template. I am running in developer mode.

I have successfully installed my theme and applied it globally in the admin, using Luma as a parent.

<vender> = SampleStore
<theme> = sampletheme

I can tell it is working because I have added _theme.less to <vender>/<theme>/web/css/source and changed the background color of the body to red, which after a cache clear is reflected on the store in my browser.

My issue is when I try to override a template not just a style change my changes are ignored and the parent Luma template is served.

I am trying to add some text after QTY on the product page, just as a test.

I went into vender/magento/ and copied module-catalog and all it's sub folders (as that is where the template for this particular change is) and paste them in my own vendor directory (not inside the <theme> directory, but right inside <vender>): <vender>/**module-catalog**

I deleted all the folders I didn't need, leaving me with view/frontend/templates/*all files*

Have I misunderstood where to place this module-catalog folder, have I missed out a step or something else? Why is my new template ignored and Luma being used?

enter image description here

I am using this guide. Specifically this section:

Template customization walkthrough

To customize or override a template:

  1. Locate the template which is associated with the page or block you want to change, using template hints in developer tools. For example, these would be located at: app/design/<vendor_name>/<module_name>/view/frontend/templates/
  2. Copy the template to your theme folder according to the template storing convention.
  3. Make the required changes.
有帮助吗?

解决方案

You need to change your path with below the structure.

app/design/frontend/SampleStore/sampletheme/Magento_Catalog/templates/product/view/addtocart.phtml

It will work.

其他提示

Suppose you want to override below file :

module-catalog/view/frontend/template/product/view/addtocart.phtml

This file can be overriden in theme by copying the file to below location :

app/design/frontend/ThemeVendorName/ThemeName/Magento_Catalog/templates/product/view/addtocart.phtml

Note: view folder shouldn't be there as we are defining area in starting(app/design/frotnend)

许可以下: CC-BY-SA归因
scroll top