I'm trying to use Drupal.settings for the first time to pass variables from PHP to JavaScript. The documentation on the topic is sparse and I have a few issues.
Is it possible to use #attached to pass through the settings rather than drupal_add_js(array('myModule' => $settings), 'setting');
? The reason I am asking is that I've been told that #attached
is the "correct" way to add settings. ( I know it is also the correct way to add files also, but not sure if it works with settings variables.)
I'm using the following code, but I can't get it to load under the DOM objects and I am stuck.
(function ($) {
Drupal.behaviors.myModule = {
attach: function(context, settings) {}
};
});(jQuery);
Any advice would be greatly appreciated. Please bear in mind that this is the first time I've set out to use Drupal.settings, so every detail is welcome and appreciated.