2

I'm trying to add a box.com file upload widget to certain pages in a block. The upload widget is an external js script. I'm adding it via a custom module, using hook_block_view,

switch ($delta) {
    case 'box_com_photo':
    $block['subject'] = t('Box File Uploads: Photography');
    $block['content'] = array(
        '#attached' => array(
        'js' => array(
            'scope' => 'content',
            'data' => 'https://app.box.com/embed/upload.js[custom widget code]',
            'type' => 'external',
          ),
        ),
      );
      break;

Regardless of the scope, it always shows up in the page header.

Suggestions??

2 Answers 2

1

Content isn't a valid region for scope, it can only be header or footer. See this documentation: https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_add_js/7

The render process runs drupal_add_js/css based on items inside of #attached.

1
  • OK, but if I change the scope to 'footer' it still shows up in the header. Jul 6, 2015 at 18:36
1

AdvAgg supports scripts in various regions. But the way you're trying to use is not supported (JS in a block).

In settings.php add this.

$conf['advagg_scripts_scope_anywhere'] = TRUE;

This allows for scripts to be put in any scope outside of the header and footer.

Anyway to answer you question I would put raw js with the script tags into the block.

switch ($delta) {
    case 'box_com_photo':
    $block['subject'] = t('Box File Uploads: Photography');
    $block['content'] = '<script src="https://app.box.com/embed/upload.js[custom widget code]" type="text/javascript"></script>';
      break;

I created a feature request for this, since we want something similar here at my work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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