jsitter's picture

I'm trying to make a complicated widget using React and need to attach the Javascript to the footer, however using 'scope' => 'footer' doesn't seem to do the trick. Perhaps I'm missing something?

Link to Code

Accepted answer

You could try testing a simple example to see if it puts it in the footer.

$element['#attached']['js'][] = array(
  'type' => 'inline',
  'data' => 'jQuery(document).ready(function () { alert("Hello!"); });',
  'scope' => 'footer',
  'weight' => 5,
);

Not sure if that'll work or not.

Comments

You could try testing a simple example to see if it puts it in the footer.

$element['#attached']['js'][] = array(
  'type' => 'inline',
  'data' => 'jQuery(document).ready(function () { alert("Hello!"); });',
  'scope' => 'footer',
  'weight' => 5,
);

Not sure if that'll work or not.

Yup. Somehow trying to do it all in one go was messing up the scope. Breaking it up into multiple simple assignments got it all working.