Javascript works fine, but i need to get my_var variable from module. At the moment its not working.
Clear my page cache and browser cache several times.
The variable 'my_var' is showing value on front end but not on backend/admin side.
Front end theme is Bartik; the admin theme is Seven.
All other variables are available on Admin side from Drupal.settings, except the one I pass from my custom module.
This works well on both themes.
alert(Drupal.settings.basePath);
This is my code.
MY_MODULE.module
/**
* Implements hook_page_build().
*/
function MY_MODULE_page_build(&$page) {
ctools_include('modal');
ctools_modal_add_js();
// HERE it is calling the js
drupal_add_js(array('MY_MODULE' => array('my_var' => 'MY_VALUE'),), 'setting');
drupal_add_js(drupal_get_path('module', 'MY_MODULE') . '/js/MY_MODULE.js');
}
MY_MODULE.js
(function ($) {
Drupal.behaviors.MY_MODULE = {
attach: function(context) {
alert("test");
alert(Drupal.settings.MY_MODULE.my_var);
}
}
})(jQuery);
On front end, it alerts with test followed by MY_VALUE, but on admin side, it shows test; Firebug then shows me:
Uncaught TypeError: Cannot read property 'my_var' of undefined
How can I fix this?