Drupal 8: Agregar elementos al encabezado de la página

Although existing in Drupal 7 as well, the #attached key in render arrays really becomes important in D8. We can no longer add any scripts or stylesheets to any page without such proper attachment to render arrays. In my last article I've shown you how to add core scripts to pages in case they were missing (which can happen for anonymous users). In essence, it is all about libraries now that get attached to render arrays. So that is most of what you'll hear about.

But libraries are not the only thing you can attach to render arrays. You can also add elements to the head of the page in a similar way you'd attach libraries. So if we wanted to add a description meta tag to all of the pages on our site, we could implement hook_page_attachments() like so     $attachments = array(
      'bootstrap_js' => array(
        '#tag' => 'script',
        '#attributes' => array(
          'src' => $js_uri,
        ),
       '#weight' => 1000,
      ),
      'bootstrap_css' => array(
        '#tag' => 'link',
        '#attributes' => array(
          'rel' => 'stylesheet',
          'link' => $css_uri,
          'media' => 'all',
        ),
       '#weight' => 1000,
      ),
    );
    foreach ($attachments as $key => $value) {
      $page['#attached']['html_head'][] = [$value, $key];
    }