Skip to content

Instantly share code, notes, and snippets.

@keeprock
Last active August 29, 2015 14:16
Show Gist options
  • Save keeprock/3990dc66d1f96d025ce8 to your computer and use it in GitHub Desktop.
Save keeprock/3990dc66d1f96d025ce8 to your computer and use it in GitHub Desktop.
Access variables from PHP in Javascript
drupal_add_js(array('VAR_JS' => $VAR_PHP), 'setting');
// Alternative
drupal_add_js(array('CUSTOM_MODULE' => array('KEY' => 'value')), 'setting');
if(settings.VAR_JS !== undefined){
}
// Alternative
Drupal.settings.CUSTOM_MODULE.KEY;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment