Magento 2.x – How to override a template file in a module

If you are creating a new module, where you want to override an existing and used template, you can perform the following and easy step:

  • Vendor/MyModule/view/frontend/layout/default.xml (or whichever you need to)
  • Vendor/MyModule/view/frontend/templates/my_new_template.phtml


And that’s it, you should now be able to see your new template. Remember to clean cache before that.

Happy coding.!