0

The goal is to include js files for custom block from custom module after the JS specified in the themes.info file. From the moduleName.module

function moduleName_block_view($delta = ''){
  $block = array();
  switch($delta){
    case 'contact_form':{
                $block['subject'] = '';
                $block['content'] = array(
                    '#markup' => build_contact($delta),
                    '#attached' => array(
                        'js' => array(
                            'http://somepath/0.0.2/contact-0.0.2.min.js' => array(
                                'type' => 'file',
                                'weight' => 1000,
                            ),
                            drupal_get_path('module', 'moduleName').'/js/contact-config.js' => array(
                                'type' => 'file',
                                'weight' => 5,
                            ),
                        ),
                    ),
                );
...
return $block;
}

The weights work for the two JS files within the custom block as specified here. Problem is that, i am unable to make these js files be imported after the js files specified in theme.info file. How to make these file import after the theme js? Thank you for help

3

You can specify the #scope attribute to control where the JS gets added. For example, you could place it in the footer, which (more likely than not) would come after your theme's JS:

'#attached' => array(
  'js' => array(
    'http://somepath/0.0.2/contact-0.0.2.min.js' => array(
    'type' => 'file',
      'weight' => 1000,
      'scope' => 'footer',
    ),
    drupal_get_path('module', 'moduleName').'/js/contact-config.js' => array(
      'type' => 'file',
      'weight' => 5,
      'scope' => 'footer',
    ),
  ),
),

Alternatively, you could implement hook_js_alter() to change the 'final' ordering of the JS files added through #attached, drupal_add_js(), .info files, etc.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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