1

I want to pass js window variables from view/frontend/templates/form.phtml to view /web/template/shipping-information.html and view/web/js/shipping-information.js How can I do it?

it is because I want to get system.xml file values in that web folder. I am able to get it in the phtml files using helper but stuck here.

can any one help?

1

2 Answers 2

0

I did write a public repository a while ago: https://bitbucket.org/magstaging/productcompare/src/master/

In this repository, I use the uicomponent technology that is widely used in Magento. But particularly, I use a file called state and this file contains the data that my module handles. And each uicomponent pulls the data using the state as a dependency.

Of course, uicomponent is complex and you may want to use something simpler but if you are already comfortable with them, then this state file is possibly something that will answer to your question

0

I found out that we can get the values using window variables use the following in phtml files to js files. view/frontend/templates/sample.phtml

<?php $helper= $this->helper('Vendor\Module\Helper\Data') ?>
  <script>
       window.variable_name = '<?php echo $helper->getMethod("configId"); ?>';
  </script>

after that use call the window.variable in html file view/frontend/web/js/sample.js

alert('config value from window variable from phtml file is ',window.variable_name);

In some way this one solved my problem.

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.