Skip to main content
reference deprecated
Source Link
subhojit777
  • 1.9k
  • 20
  • 29

In your page.tpl.php file:

$my_settings = array(
  'message' => $message,
);

drupal_add_js(array('my_settings' => $my_settings), 'setting');

Then in your JavaScript file you can access $message variable like this:

var message = Drupal.settings.my_settings.message;

Reference: HOWTO: Pass PHP variables to JavaScriptThe Drupal JavaScript API

In your page.tpl.php file:

$my_settings = array(
  'message' => $message,
);

drupal_add_js(array('my_settings' => $my_settings), 'setting');

Then in your JavaScript file you can access $message variable like this:

var message = Drupal.settings.my_settings.message;

Reference: HOWTO: Pass PHP variables to JavaScript

In your page.tpl.php file:

$my_settings = array(
  'message' => $message,
);

drupal_add_js(array('my_settings' => $my_settings), 'setting');

Then in your JavaScript file you can access $message variable like this:

var message = Drupal.settings.my_settings.message;

Reference: The Drupal JavaScript API

Source Link
subhojit777
  • 1.9k
  • 20
  • 29

In your page.tpl.php file:

$my_settings = array(
  'message' => $message,
);

drupal_add_js(array('my_settings' => $my_settings), 'setting');

Then in your JavaScript file you can access $message variable like this:

var message = Drupal.settings.my_settings.message;

Reference: HOWTO: Pass PHP variables to JavaScript