2

I have Magento 2.2.4 version, And I want to overwrite Magento_Checkout/template/minicart/item/default.html file in my custom module. For this, I created require-jsconfig.js file at below path

/app/code/Namespace/Module/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
          'Magento_Checkout/template/minicart/item/default.html': 'Namespace_Module/template/minicart/item/default.html'
        }
  }
};

removed "var" folder from root and remove "pub/static/frontend" folder and run below command:

php bin/magento setup:static-content:deploy

But mini cart is showing blank. Can anyone help me to understand my mistake?

1

Magento provides requirejs-config.js files for overriding the js & html file to enhance the functionality of the existing js & html files by simply manipulating them into your custom module.

To do that just follow the following guidelines.

  • Create & register your custom module & create requirejs-config.js file at below location

Magento_root/app/code/Vendor/Module/view/frontend/requirejs-config.js

And below code in your requirejs-config.js

var config = {
    map: {
        '*': {
          'Magento_Checkout/template/minicart/item/default.html': 
              'Vendor_Module/template/minicart/item/default.html'
        }
  }
};

If you required to do very minor changes then instead of creating a module you can directly do that by simply overriding it with the help of your theme. For that just follow the below guidelines.

  • Just copy the file from the below location

vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html

  • Place it into your custom theme at the below location & make your changes there into that file

Magento_root/app/design/Vendor/theme/Magento_Checkout/web/template/minicart/item/default.html

So we can override any html file in this way.

Note: After making the changes to deploy it properly please run the below commands

php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento c:f                     
  • I tried to overwrite through requirejs-config.js not working – Nilava Chakraborty Mar 6 at 10:15
  • Did you checked that is it calling your page or the default old page there in your cart section? try to make different changes into both of them & see which change is coming there. try to deploy your static content & before that delete the generated folder & the var/cache folder contents. – Abhishek Tripathi Mar 6 at 10:20
  • After doing that I checked, it is calling the default file only. Not the updated one. But I can able to see my updated code under pub/static section. And I run below all command rm -rf pub/static/frontend/ , rm -rf var/, rm -rf generated/, php bin/magento setup:upgrade, php bin/magento setup:di:compile, php bin/magento setup:static-content:deploy, php bin/magento indexer:reindex, php bin/magento cache:clean, php bin/magento cache:flush – Nilava Chakraborty Mar 6 at 11:05
  • Are you working on your local system or on the server? If you are working on the server then there is a possibility that some cache is set there try to remove that cache & also try with different browsers or browsers into incognito/safe mode because it can be possible that your browser cache is loading the old data! – Abhishek Tripathi Mar 6 at 11:25
  • I am working on a server and open site in incognito/safe mode only – Nilava Chakraborty Mar 6 at 11:27

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.