get('color') ?? '#000000'; $variables['#attached']['html_head_link'][] = [ [ 'rel' => 'preload', 'as' => 'style', 'href' => \Drupal::service('extension.list.theme')->getPath('your_theme_name') . '/css/mobile_facets.css', // Adjust if needed. ], ]; // Add the CSS variable to attributes. $variables['html_attributes']['style'] = '--mobile_facets-color: ' . $color . ';'; // Optionally attach the library if not already. //$variables['#attached']['library'][] = 'mobile_facets/mobile_facets'; }