I am new to Magento 2 and I’m not quite understand its structure yet. I’m using its sample data to investigate code. I want to override a .phtml file by using a custome module. The file I want to override is:
vendor/magento/module-customer/view/frontend/templates/account/dashboard/info.phtml
So far, I create a file in this path:
src/app/code/NewModule/NewModuleTest/view/frontend/templates/customer/account/dashboard/info.phtml
I copy that original file to this and make some simple changes like add a tag, changing text. After that, I run command:
bin/magento setup:upgrade
bin/magento cache:clean
But nothing happen. I don’t know if I’m missing anything. I also clear browser’s cache. Please help me. Any ideas are appreciated. Thank you all!
P/s: I don’t know if this is related, I install Magento by this repo on Github: Docker Magento
2
Answers
I figured out how to do this
Identify files you want to override
vendor/magento/module-customer/view/frontend/templates/account/dashboard/info.phtml
vendor/magento/module-customer/view/frontend/layout/customer_account_index.xml
Override steps
app/code/NewModule/NewModuleTest/view/frontend/layout/customer_account_index.xml
referenceBlock
tag and original block’s ‘name’/app/code/NewModule/NewModuleTest/view/frontend/templates/customer/account/dashboard/info.phtml
Then it's done!
You need create a layout file to update this .phtml template, like this:
and add this content:
The
customer_account_dashboard_index.xml
file targets the specific page you want to modify. It uses the tag to modify the customer_account_dashboard_info block, setting the template to your custom .phtml file