Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Is there any way to add some variables to Drupal.settings without drupal_add_js (with setting argument).

I'm creating a site that has a custom ctools popup style but I'm not feeling good with drupal_add_js. How can I add this JavaScript snippet to the page using the theme's .info page ? I'm not sure how can I merge my custom variables (literally, they are just static) to Drupal.settings so ctools module can pick them up as it was added via regular drupal_add_js call.

Thank you in advance.

share|improve this question
    
No there's no way to do that, you need to use drupal_add_js or an #attached property on a render array –  Clive Sep 26 '13 at 7:55
    
Ohh.. I really wish Drupal has a little more magic to do that. Anyway, thank you very much for your help Clive. –  Ayesh K Sep 26 '13 at 7:59
    
No worries, I haven't put it in as an answer 'cos I'm hoping someone will know some sort of dark magic to prove me wrong :) –  Clive Sep 26 '13 at 8:01
    
With using JS injector you can add js code directly on the UI, and it provides conditionnals conditions (match pages urls) –  pico34 Sep 26 '13 at 8:08
    
@pico34 Can you use JS injector to manipulate Drupal.settings? That would be pretty cool –  Clive Sep 26 '13 at 8:15
show 2 more comments

1 Answer 1

up vote 1 down vote accepted

Maybe I am missing a point to the question, but you should be able to do

scripts[] = path/to/your/script.js

in the .info file of your theme. And within the script file something like

(function ($) {
$(document).ready(function () {
    Drupal.settings.yoursetting = {};
    Drupal.settings.yoursetting.property = some_value;
});
})(jQuery);

or use the Drupal.behaviors convention.

share|improve this answer
    
YOU ARE GENIUS WAYNE! This worked perfectly. Thank you very very much. –  Ayesh K Sep 27 '13 at 5:25
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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