I've a drupal 8 website, where in every page, I would like to add a noscript tag for every script tag. In drupal 8, in html.html.twig, I saw the scripts variable in missing. So how do I do that in Drupal 8?


I wound up just putting the <noscript> tag into my html.html.twig template. There is a NoScript Tag module, but I didn't feel like adding a module to my site for this purpose.


You can do it in a custom module (MYMODULE.module):

use Drupal\Core\Render\Markup;

function MYMODULE_page_attachments(array &$page) {
  $fallback = '<link href="fallback.css" rel="stylesheet" />';
  $noscript = array(
    '#tag' => 'noscript',
    '#value' => Markup::create($fallback),
  $page['#attached']['html_head'][] = [$noscript, 'mymodule'];

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.