0

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..

Thanks!

2

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:

Drupal.settings.myModule.key

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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