Aram Boyajyan: Drupal 8 add inline JavaScript to a page

Drupal 8 add inline JavaScript to a page

Separate JS files are good but in certain cases (e.g. tracking scripts) it might be useful to just add a piece of inline code to a specific page.

This can easily be achieved from a custom module by implementing hook_page_attachments(), checking the page you are on and adding the JS code to the HTML head.

superuser
Tue, 18/02/2020 – 12:06