I'd like to know what is the best approach to add a custom knockout component to the checkout sidebar in Magento 2, an example assuming we already have a custom module would be great
UPDATE:
As I needed a placeholder different than the "summary", I followed Sohel's answer and also did those steps
Override sidebar template in module's requirejs-config.js:
var config = {
map: {
'*': {
'Magento_Checkout/template/sidebar.html': 'SR_MagentoCommunity/template/sidebar.html',
sidebar: 'SR_MagentoCommunity/js/sidebar'
}
}
};
Add a new region called "timer" in the new overriden sidebar.html template:
<div id="opc-sidebar"
data-bind="afterRender:setModalElement, mageInit: {
'Magento_Ui/js/modal/modal':{
'type': 'custom',
'modalClass': 'opc-sidebar opc-summary-wrapper',
'wrapperClass': 'checkout-container',
'parentModalClass': '_has-modal-custom',
'responsive': true,
'responsiveClass': 'custom-slide',
'overlayClass': 'modal-custom-overlay',
'buttons': []
}}">
<!-- ko foreach: getRegion('summary') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
<div class="opc-block-shipping-information">
<!-- ko foreach: getRegion('shipping-information') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
<!-- ko foreach: getRegion('timer') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!--/ko-->
</div>
Update checkout_index_index.xml to place the component in the new region:
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="timer" xsi:type="array">
<item name="component" xsi:type="string"> SR_MagentoCommunity/js/timer</item>
<item name="displayArea" xsi:type="string">timer</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string"> SR_MagentoCommunity/timer</item>
</item>
</item>
</item>
</item>
And this is the final result: