Passing values from PHP to Javascript with Drupal.settings Using drupal_add_js function I have used hook_process_page to add our drupal_add_js function. myModule is the module name you can specify, in my case I have used myModule for example Another variable ”userid” is used for getting current user’s id These variables can be accessed is js file using drupal behaviors. in colse type Drupal.settings.myModule It results in our key:value which was defined in hook_process_page() Added conditions for both settings in behaviors. Our JS recognizes the variable from PHP and alerts our custom message. Similarly for second variable “userid” We are logged in as admin modify value to check if our changes reflects correctly. Hard refresh Thanks for watching 🙂

Drupal 7 Passing values from PHP to Javascript with “Drupal.settings”

One thought on “Drupal 7 Passing values from PHP to Javascript with “Drupal.settings”

  • October 4, 2017 at 5:49 pm

    Was excited to see this tut but…Wish there was sound!


Leave a Reply

Your email address will not be published. Required fields are marked *