I know it's perfectly possible to pass PHP variables to JS but what if the JS file is initiated from the theme.info file? Can you access it in template.php or? Please some advice..



1 Answer 1


You don't access the Javascript file in PHP, rather, you tell Drupal to send values to Javascript variables and then access those from your Javascript files. You would use drupal_add_js.

For example, in template.php add:

drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');

Then in your Javascript file, you can access that variable as:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.