1

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.
  • Have you done setup:static-content:deploy and cache:flush command after all ? – Nikunj Vadariya Jun 27 '18 at 12:03
  • @NikunjVadariya I am in developer mode so not required, thanks though. I will add that to my main post for clarity (I have cleared cache and deleted /generated) – GoldenGonaz Jun 27 '18 at 12:09
  • I have added my answer for your fixe, Check and let me know if still any issue – Nikunj Vadariya Jun 27 '18 at 12:16
2

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.

  • This worked great, it is now using my template :) However I have a new issue, the style has gone missing on the page. Does this mean when a template is overridden, the css alone will not default back to Luma? I must also override the css? – GoldenGonaz Jun 27 '18 at 13:00
  • @GoldenGonaz follow the magento guide: devdocs.magento.com/guides/v2.2/frontend-dev-guide/themes/… – Nikunj Vadariya Jun 27 '18 at 13:05
  • Thanks, this is what I was looking at but wasn't able to find an answer. I will take another look :) – GoldenGonaz Jun 27 '18 at 13:07
  • Incase anyone else reads this with the style loss issue. The reason was I had created web/css/source/_theme.less to change the body background color. This was for some reason losing all the styles from the whole site. Once I removed this file, the styles reappeared globally. I will need to write new styles but I assume (I don't know for sure) that I will extended them instead. – GoldenGonaz Jun 27 '18 at 16:16
1

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)

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.