Docs
KnockoutJS communication
KnockoutJS communication
How to make Zermatt communicate with KnockoutJS.
Here is how to make Zermatt talk with Knockout.
Open these files from the /vendor/maddlen/module-zermatt-examples/view/frontend directory:
templates/knockout.phtmlweb/js/knockout.js
knockout.phtml
- We use AlpineJS
@input.dedounceto dispatch thezermatt_example:alpine_inputevent with itsvaluetaken from the$eventobject passed by AlpineJS. - We declare a Knockout template with its data bound to the
zermatt_example_knockoutKnockout component... - ... which is declared just below in the regular Magento way.
knockout.js
- We initiate the
messageobservable. - We initialize the component and make it listen to the
zermatt_example:alpine_inputevent... - ... and update the
messageobservable.