I use many template files in my modules via hook theme. In order to pass variable to JS files I use the method described here: https://www.drupal.org/node/304258 in the .tpl.php files:
$my_settings = array( 'basePath' => $base_path, 'animationEffect' => variable_get('effect', 'none') ); drupal_add_js(array('myModule' => $my_settings), 'setting');
and then in the .js files:
var basePath = Drupal.settings.myModule.basePath; var effect = Drupal.settings.myModule.animationEffect;
For the first time (it seems) I’m trying to pass variables to JS from .tpl files located in my theme folder. Suppose I have a content type called ‘cars’, I craete a page-cars.tpl.php template file in my theme folder which automatically applies to all car pages. But in these tpl files I can’t pass variables to JS using the method described above. I tried switching ‘myModule’ to ‘myTheme’ but Drupal won’t recognize it as a defined setting
As per Clive’s instructions I added to the my_theme_preprocess_content_type(&$variables) function and it works! (thanks Clive)