Sending Parameters or Settings to Javascript in Drupal 7

June 18, 2021
There is a simple way to do this in Drupal 7, using the function drupal_add_js and creating an array with the data we want to make accessible: [prism:php] $settings = array ( 'foo' => 'bar', 'name' => 'john', ); drupal_add_js( array ("my_module" => $settings), 'setting'); [/prism:php] Notice that we are using the 'setting' parameter on drupal_add_js, this way we indicate to the function that we are passing settings. After adding the settings you will be able to access this information on your javascript this way: [prism:php] var name = Drupal.settings['my_module']['name']; [/prism:php]