9

How can we override a knockout template in a custom module? I know how we can do this in our own theme but I need this in a module.

For example I like to override this file: vendor/magento/module-checkout/view/frontend/web/template/shipping-address/form.html

Is this possible?

1
  • An idea: create a mixin on the component and set the template from within the mixin/component. Commented May 1, 2017 at 16:02

1 Answer 1

10

Yes you can override a knockout template in a custom module, just did it, in your module create a requirejs-config.js file and place it in your module:

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

In the file add the configuration to specify the override:

var config = {
    map: {
        '*': {
            'Magento_Checkout/template/billing-address':
                'Namespace_Module/template/billing-address'
        }
    }
};
5
  • 2
    You need to drop the .html extension from the paths...
    – Quinten
    Commented Jul 19, 2019 at 10:23
  • How does it work if the knockoutjs file is in base folder?
    – Black
    Commented Sep 28, 2020 at 13:25
  • 1
    @Black I haven't tested it, but maybe you would create the override in this path: app/code/Namespace/Module/view/base/requirejs-config.js
    – SantiBM
    Commented Sep 29, 2020 at 6:38
  • @SantiBM, doesnt work either
    – Black
    Commented Sep 29, 2020 at 7:49
  • If you figured it out, then please answer it here: magento.stackexchange.com/questions/323215/…
    – Black
    Commented Sep 29, 2020 at 12:44

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.