0

I have a custom module installed via composer and the path is vendor/company/module/src/registration.php.

I want to override some of these files like vendor/company/module/src/view/template/frontend/main.phtml but no path I tried worked:

app/code/Company/Module/src/view/template/frontend/main.phtml
app/code/Company/Module/view/template/frontend/main.phtml
app/design/frontend/package/theme/Company_Module/src/view/template/frontend/main.phtml
app/design/frontend/package/theme/Company_Module/view/template/frontend/main.phtml

I hope there is an easy way to do it and you don't have to create a separate module and extend.

8
  • You can override by using theme as you mentioned , is there any issue using themes. Commented Sep 22, 2016 at 13:21
  • @krishnaijjadaati95Dev yes, it doesn't get parsed, inserted die() or incorrect php syntax. Commented Sep 22, 2016 at 13:24
  • @krishnaijjadaati95Dev deleted var folder and flushed cache Commented Sep 22, 2016 at 13:24
  • @ Claudiu Creanga first test whether the module is working or not, then you can migrate the templates into theme Commented Sep 22, 2016 at 13:27
  • @krishnaijjadaati95Dev the module is working properly. if I go to website.com/module-url it is showing up properly. if I edit main.phtml in vendor the change is being picked up, but not if I edit ../theme/.. Commented Sep 22, 2016 at 13:29

2 Answers 2

2

Copy templates folder from

template/frontend/main.phtml

Keep your code in

app/design/frontend/package/theme/Company_Module/template/frontend/main.phtml 

What i have tried Taken the code from

\vendor\magento\module-customer\view\frontend\templates\form\login.phtml

And placed

\vendor\magento\theme-frontend-luma\Magento_Customer\templates\form\login.phtml

Working as expected.

4
  • yes, disregarded view/frontend and it worked. thanks! Commented Sep 22, 2016 at 13:46
  • 1
    and I guess if I want to override Block/Phpfile.php i will have to extend Commented Sep 22, 2016 at 13:50
  • it makes sense though so that composer can update it properly Commented Sep 22, 2016 at 13:51
  • Yes, as well as you know if you want to override only few functions use PLUGIN, or entire class use preference by extending core class. Commented Sep 22, 2016 at 13:53
0

Update for Magento 2.2 & 2.3 You have to place your code in

app/design/frontend/package/theme/Company_Module/templates/main.phtml

where Company_Module is the name on etc/module.xml, and no need to put frontend again after module namen and the name of folder is "templates*" and no "template"

Another exemple to override

vendor/smile/elasticsuite/src/module-elasticsuite-catalog/view/frontend/web/template/autocomplete/category.html
vendor/smile/elasticsuite/src/module-elasticsuite-core/view/frontend/web/template/autocomplete/term.html

Override has to be on two different modules and on web folder

app/design/frontend/Package/Name/Smile_ElasticsuiteCore/web/template/autocomplete/term.html
app/design/frontend/Package/Name/Smile_ElasticsuiteCatalog/web/template/autocomplete/category.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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