In Magento 2 templates I've found some ko statements such as

<form class="form form-shipping-address" id="co-shipping-form" data-bind="attr: {'data-hasrequired': $t('* Required Fields')}">
<!-- ko foreach: getRegion('before-fields') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<div id="shipping-new-address-form" class="fieldset address">
    <!-- ko foreach: getRegion('additional-fieldsets') -->
    <!-- ko template: getTemplate() --><!-- /ko -->
    <!-- ko if: (isCustomerLoggedIn) -->
    <div class="field choice" data-bind="visible: !isFormInline">
        <input type="checkbox" class="checkbox" id="shipping-save-in-address-book" data-bind="checked: saveInAddressBook" />
        <label class="label" for="shipping-save-in-address-book">
            <span data-bind="i18n: 'Save in address book'"></span>
    <!-- /ko -->

I understood it has something to do with knockoutjs but I'm not used of this library at all.

  • how does Magento process such statements ?
  • how to use those statements in a custom module ?

That's a pretty wide open question, but from what I understand of Knockout, those comments aren't processed by Magento at all -- they're Knockout syntax for creating container-less statements. i.e. it's the knockout javascript library that processes them.

Probably best to get started with the official docs until someone writes up a tutorial on how Magento integrates with Knockout (similar to my RequireJS article)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.