Skip to main content

The code that finally got it included an important change with regard to @AyeshK 's answer. The [attached] is not put at the top level if $page , but inside ['content'] or ['header'].
The

The adapted code from the Format#1 is now:
function MODULE_page_alter(&$page) { $my_path = drupal_get_path('module', 'MODULE' ); $page ['content']['#attached']['js'][] = array( 'type'=>'file', 'data' => $my_path . '/module_test.js' ); }

Thank you @AyeshK and @Beebee for helping to sort this out.

function MODULE_page_alter(&$page) {
  $my_path = drupal_get_path('module', 'MODULE' );
  $page ['content']['#attached']['js'][] = array(
    'type'=>'file',
    'data' => $my_path . '/module_test.js'
  );
}  

The code that finally got it included an important change with regard to @AyeshK 's answer. The [attached] is not put at the top level if $page , but inside ['content'] or ['header'].
The adapted code from the Format#1 is now:
function MODULE_page_alter(&$page) { $my_path = drupal_get_path('module', 'MODULE' ); $page ['content']['#attached']['js'][] = array( 'type'=>'file', 'data' => $my_path . '/module_test.js' ); }

Thank you @AyeshK and @Beebee for helping to sort this out.

The code that finally got it included an important change with regard to @AyeshK 's answer. The [attached] is not put at the top level if $page , but inside ['content'] or ['header'].

The adapted code from the Format#1 is now:

function MODULE_page_alter(&$page) {
  $my_path = drupal_get_path('module', 'MODULE' );
  $page ['content']['#attached']['js'][] = array(
    'type'=>'file',
    'data' => $my_path . '/module_test.js'
  );
}  
Source Link
Dalmaz
  • 510
  • 4
  • 24

The code that finally got it included an important change with regard to @AyeshK 's answer. The [attached] is not put at the top level if $page , but inside ['content'] or ['header'].
The adapted code from the Format#1 is now:
function MODULE_page_alter(&$page) { $my_path = drupal_get_path('module', 'MODULE' ); $page ['content']['#attached']['js'][] = array( 'type'=>'file', 'data' => $my_path . '/module_test.js' ); }

Thank you @AyeshK and @Beebee for helping to sort this out.