0

/app/design/frontend/Vendor/custom_theme/Magento_CheckoutAgreements/templates/additional_agreements.phtml

I have this code inside .phtml:

<div data-bind="scope: 'checkout-agreements-component-scope'" class="checkout-agreements-block">
    <!-- ko template: getTemplate() --><!-- /ko -->
</div>
<script type="text/x-magento-init">
    {
        "*": {
            "Magento_Ui/js/core/app": {
                "components": {
                    "checkout-agreements-component-scope": {
                        "component": "Magento_CheckoutAgreements/js/view/checkout-agreements",
                        "agreements": <?php /* @noEscape */ echo $agreementJson; ?>,
                        "isVisible": true,
                        "exampleMessage": "<?php echo 'Hello Magento Stack Exchange!'; ?>",
                        "sarfaraj": "<?php echo 'I am Back....!' ?>"
                    }
                }
            }
        }
    }
</script>

/app/design/frontend/Vendor/custom_theme/Magento_CheckoutAgreements/web/js/view/checkout-agreements.js

inside .js:

return Component.extend({
            defaults: {
                exampleMessage: 'Default Text Ready',
                sarfaraj: 'Raj',
                template: 'Magento_CheckoutAgreements/checkout/checkout-agreements'
            },              

            initialize: function() {
                this._super();
                console.log(this.exampleMessage);
                this.message = ko.observable(this.exampleMessage);
                console.log(this.sarfaraj);
                this.FIR = ko.observable(this.sarfaraj);
            }
    });

/app/design/frontend/Vendor/custom_theme/Magento_CheckoutAgreements/web/template/checkout/checkout-agreements.html

inside .html:

<h2 data-bind="text: message"></h2>
<h3 data-bind="text: FIR"></h3>

My OUTPUT at Checkout page:

enter image description here

Help Me. Thanks.

3
  • I don't have time to look at this in depth atm but can you try one quick thing please, try adding the text/x-magento-init call before your data-bindings. I don't think this is the issue but I have seen stranger things happen!
    – Ben Crook
    Oct 26, 2017 at 14:22
  • And can you include the require() call in your JS code please just to make sure that is ok.
    – Ben Crook
    Oct 26, 2017 at 14:24
  • @BenCrook, Thanks for reply & check this one time. Oct 27, 2017 at 5:03

1 Answer 1

0

@sarfaraj this actually helps in above situation.

How to pass a Magento 2 variable to KnockoutJS

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.