I'm working on a credit card (CC) payment module.
I see that Magento 2 already offers a template for CC payments but it contains only the form needed for the payment.
It does not have the radio button that I can check during checkout.
So if I create my payment method renderer like this.
define(
[
'Magento_Payment/js/view/payment/cc-form'
],
function (Component) {
'use strict';
return Component.extend({
defaults: {
template: 'Magento_Payment/payment/cc-form'
},
isActive: function() {
return true;
},
getCode: function() {
return 'payment_code_here';
}
});
}
);
my payment section in the checkout would look like this (Check/money order is an other payment method):
And I want it to look like this:
I know that I can create my own template and define the method renderer like this:
define(
[
'Magento_Payment/js/view/payment/cc-form'
],
function (Component) {
'use strict';
return Component.extend({
defaults: {
template: '<Vendor>_<Module>/payment/form'
},
isActive: function() {
return true;
},
getCode: function() {
return 'payment_code_here';
}
});
}
);
And in that template add the markup for the radio button and just copy/paste the default cc-form template where I need it, but I'm trying to avoid that.
Is there a way to include an other template inside my template?
This may be more of a KO question than Magento.
To explain it better…
My custom template looks like this:
<my custom code here />
<code copied from cc-form />
<some other custom code here />
I want to replace <code copied from cc-form />
with an include of some kind that will fetch the content from cc-form
.
Best Answer
I'm not sure I understand the question fully, do you mean you want to call a KO HTML template from another template/module?
If so the I believe the following markup works (unable to test currently):
Or alternatively you can define the template in an object and pass a property like so: