function my_utlities_page_attachments(array &$page) {
$page['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => 'console.log("Check the log.");',
'#weight' => 2,
],
'js_log_script',
];
}
A slightly more elegant way might be to separate the array into its own variable
function my_utlities_page_attachments(array &$page) {
$js_log = [
[
'#type' => 'html_tag',
'#tag' => 'script',
'#value' => 'console.log("Check the log.");',
'#weight' => 2,
],
];
$page['#attached']['html_head'][] = [$js_log, 'js_log_script'];
}
- Log in to post comments