Magento – Magento 2 : How to debug knockoutjs getRegion() bindings

jslayoutknockoutjslayoutmagento2

Shipping address is displayed using below knockout js code.
I am having a hard time finding the back-end code that's setting data for getRegion('ship-to') function even though I could see the UI JS template component configuration. Does anyone have any input on how this data is being pulled on the payment/review page in Magento 2.x?

<!-- ko foreach: getRegion('ship-to') -->
    <!-- ko template: getTemplate() -->
    <!--/ko-->
<!--/ko-->

Best Answer

<!-- ko foreach: getRegion('ship-to') -->

invokes the following piece of code from checkout_index_index.xml layout file

<item name="displayArea" xsi:type="string">shipping-information</item>
<item name="children" xsi:type="array">
    <item name="ship-to" xsi:type="array">
        <item name="component" xsi:type="string">Magento_Checkout/js/view/shipping-information/list</item>
        <item name="displayArea" xsi:type="string">ship-to</item>
    </item>
</item>

It essentially asks to load uiComponent corresponding to the region i.e Magento_Checkout/js/view/shipping-information/list and loop and render through all its children.

<!-- ko template: getTemplate() -->

renders HTML templates corresponding to each component, you can know template for a uiComponent by looking into its code. For eg. for current uiComponent i.e Magento_Checkout/view/frontend/web/js/view/shipping-address/list.js following code tells us that the template for it is Magento_Checkout/shipping-address/list.html located under view/frontend/web/template/shipping-address directory.

return Component.extend({
        defaults: {
            template: 'Magento_Checkout/shipping-address/list',
            visible: addressList().length > 0,
            rendererTemplates: []
        },

All the addresses are maintained in a global js window object called customerData, if you specifically want to know how data is coming from php. This answer of mine might help.

Please feel free to ask any questions.

Related Topic