I am currently writing a module and I am trying to pass some variables to the Drupal.settings
.
My module uses the following code.
function bcc_preprocess_views_view(&$vars) {
drupal_add_js(array('modulname' => array('key' => 'value')), 'setting');
drupal_add_js(drupal_get_path('module', 'modulname') .'/script.js');
}
The script.js content is the following.
(function ($) {
console.log(Drupal.settings.modulname);
})( jQuery );
The output I find in the log is undefined, but when I check the content of Drupal.settings.modulname
from the browser, it gives me the desired value.
When I add this code, the log shows the right values.
drupal_add_js('jQuery(document).ready(function({console.log(Drupal.settings.royal)});', 'inline');
What is wrong with that? What is the correct code to use?