Magento template support script tag with X-MAGENTO-INIT declaration. You can pass dynamic PHP values to Javascript from a template file.
create demo.phtml file in your module to pass dynamic PHP value to Javascript,
3x Magento Master
Magento template support script tag with X-MAGENTO-INIT declaration. You can pass dynamic PHP values to Javascript from a template file.
create demo.phtml file in your module to pass dynamic PHP value to Javascript,
Magento 2 template supports require JS declaration using X-MAGENTO-INIT. You can define require js with the Magento PHTML template file.
Require js loaded as AMD (Asynchronous module definition) based approach.
Benefit:
Declare JS using text/x-magento-init will be loaded after the page DOM is loaded completely. It will improve the page load time.
You can get a list of all the used knockout components on the current page using uiRegistry.
Knockout Components will be defined using the custom module and Magento native code contains a lot of predefined knockout components like minicart, authentication, customer, etc…
You can also fetch a custom component by its name in the get() method of the uiRegistry object.