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'
);
}