How to add html head link tag when a specific block is loaded I have a custom block with its own twig template file.

I want to add an html head link tag when this block is loaded.
ex: &lt;link rel="import" href="test.html"&gt;

In the twig template I can use attach_library to add css/js to , but I don't know how to add html imports in twig.

Is it possible to achieve this using mytheme_preprocess_block function, or any other hook?

I can add the html head link tag in mytheme_page_attachments_alter but I don't know how to limit this to only when my custom block is loaded.

Thank you.
See NodeViewController::view():

  $build['#attached']['html_head_link'][] = array(
    array(
      'rel' =&gt; $rel,
      'href' =&gt; $node-&gt;url($rel),
    ),
    TRUE,
  );


You can add html_head_link #attached elements anywhere, including in your block, and it will bubble up and be added to any page that shows your block.