It's possible to pass a variable on attach_library in a template on Drupal 8?
.module

/**
 * Implements hook_ENTITY_TYPE_load()
 */ 

function my_module_node_load($nodes) {
    foreach ($nodes as $node) {
      if ($node-&gt;getType() == 'article') { // is of article content type
        $data_passer = &amp;drupal_static('my_module_node_field_name');
        // use &amp;drupal_static to pass value between hooks. 
        $data_passer = $node-&gt;field_name-&gt;value;
      }
    }
}

/**
 * Implements hook_page_attachments()
 */
function my_module_page_attachments(array &amp;$attachments) {
    if (!empty(&amp;drupal_static('my_module_node_field_name'))) {
      $data_passer = &amp;drupal_static('my_module_node_field_name'); 
      $node_field_name = $data_passer;
      $attachments['#attached']['drupalSettings']['my_variable'] = $node_field_name;     
    }
  }
}


.js

(function ($, Drupal, drupalSettings) {
  Drupal.behaviors.my_behaviour = {
    attach: function (context, settings) {

      alert(drupalSettings.my_variable); //alerts passed in node field_name

    }
  };
})(jQuery, Drupal, drupalSettings);