How can I add a variables to my page.html.twig file? I'm trying to add a variable that i can use in page.html.twig that will add a class to the header region if a field in the node exists.

In template_preprocess_page() i've tried doing the following and have not been able to add a variable:

function theme_preprocess_page(&amp;$variables){
  $variables['header_attributes']['class'] = [];
  $variables['header_attributes']['class'] = array_merge($variables['header_attributes']['class'], ['myClassHere']);
}


I based this off the example for menu preprocess but no new class was added to the  ta
There is no index called header_attributes inside $variables array no need to create it, there is page index just use it:
Try this out:

function [yourThemeName|yourModuleName]_preprocess_page(&amp;$variables){
  $variables['page']['header_attributes']['class']= 'myClassHere';
}


Note don't forget to clear cache.
In your twig you will get your class by:

page['header_attributes']['class']