I'm trying to understand knockoutjs in magento2.especially custom template binding.I'm not able to get idea flow of rendering this.

Can any one have idea how it works? atleast Where can I find definition of getTemplate?

<!-- ko if: (!quoteIsVirtual) -->
            <!-- ko foreach: getRegion('customer-email') -->
                <!-- ko template: getTemplate() --><!-- /ko -->

2 Answers 2



file. look at following line

<item name="component" xsi:type="string">Magento_Checkout/js/view/shipping</item>


this is your js file. Open it. Look
template: 'Magento_Checkout/shipping'
this is the template file for this JS.

Go back to

line 122 (M2 2.0.0-rc)
<item name="children" xsi:type="array">
here you can see some child node. like

<item name="customer-email" xsi:type="array">


is responsible for current template rendering that means


Open it, then you can see following code snippet

<!-- ko foreach: getRegion('additional-login-form-fields') -->
            <!-- ko template: getTemplate() --><!-- /ko -->
            <!-- /ko -->

this 'additional-login-form-fields' node is the child node of 'customer-email' .

For your code snippet, if quote is not virtual then pick ko

foreach: getRegion('customer-email')
which is child node name and render its template.

  • getRegion('customer-email') means <item name="customer-email" xsi:type="array">. Is it correct? i mean it will iterate child nodes of that. Commented Nov 12, 2015 at 9:16
  • its render only current template. I updated the answer.
    – Sohel Rana
    Commented Nov 12, 2015 at 9:34
  • thanks for your response.so many times in xml ..core team using <item name="component" xsi:type="string">uiComponent</item> .so which js file consider in this case? Commented Nov 12, 2015 at 10:41
  • yes. look following file Magento/Ui/view/base/requirejs-config.js . here uiComponent is declare as js.
    – Sohel Rana
    Commented Nov 12, 2015 at 12:05
  • How to get Site URl, Checkoutpageurl in any of the knockout template ? Commented Aug 13, 2016 at 7:16

You can find defination of getTemplate from,


file from line no. 255 to 257.

  getTemplate: function () {
                return this.template;
  • above code based on magento 2.0.0 general availability. Commented Nov 19, 2015 at 9: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.