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.

Consider

drupal_add_js(array(
  'radio86_media' => array('barfoo' => 'booboo')), 'setting'
);    

and

$form['#attached']['js'] = array(
  drupal_get_path('module', 'radio86_media') . '/select_media.js', 
);    

These two 'lines' work well separately, but I think they could (and should) be combined so that the variable setting is set on the second line, combining the logic.

I've been fumbling around it and just can't get it to work. With this current way, I can console.log the barfoo variable via JS by using Drupal.settings.radio86_media.barfoo so it does work, but I really would like to have it combined.

Any suggestions greatly appreciated!

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I never tried, but I guess you can do it like that :

$form['#attached']['js'] = array(
  array(
    'data' => drupal_get_path('module', 'radio86_media') . '/select_media.js',
    'type' => 'file'
  ),
  array(
    'data' => array('radio86_media' => array('barfoo' => 'booboo')),
    'type' => 'setting'
  )
);

According the documentation you should be able to add settings and files.

share|improve this answer
 
The select_media.js gets loaded just fine, but the variable is undefined. I tried swapping the arrays places so that the variable is created before the .js is included, but it did not help either. –  red Sep 21 '11 at 9:55
 
I changed something in my code (just added 'type' => 'setting' instead of 'setting'. Can you try again ? –  yvan Sep 21 '11 at 10:02
 
Thank you good ser! –  red Sep 21 '11 at 10:16
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.