I have set theme handler for a form in Drupal and this handler has a template file. What is the easiest way to send a value from PHP to Javascript in that include file?
Take the 2-minute tour
×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.
migrated from stackoverflow.com Feb 20 '12 at 20:13
This question came from our site for professional and enthusiast programmers.
The standard way to do this in Drupal is with drupal_add_js, using the "setting" type, e.g.:
That will make the variable available on the JS side at Drupal.settings.variableName. |
|||
|
Few more examples on drupal_add_js, It's better to specify your module name while adding JS variable to avoid any issues,
In case you want to execute some JS code after the DOM is initialized,
|
|||
|
Easiest way is just to echo it out into a script tag.
If Drupal uses a templating language, you need to replace the |
|||||||||||||
|