get('color') ?? '#000000'; // Preload the CSS from the module path (theme-agnostic). $css_path = \Drupal::service('extension.list.module')->getPath('mobile_facets') . '/css/mobile_facets.css'; $variables['#attached']['html_head_link'][] = [ [ 'rel' => 'preload', 'as' => 'style', 'href' => $css_path, ], ]; // Add the CSS variable to attributes (global across all themes). $variables['html_attributes']['style'] = '--mobile_facets-color: ' . $color . ';'; // Optionally attach the library if not already (loads CSS from module). //$variables['#attached']['library'][] = 'mobile_facets/mobile_facets'; }