I am trying to load an asset library in my Drupal 8 custom theme. I have created the library and can load it via mytheme.info.yml file. However, if I try the load it using hook_page_attachments() in the mytheme.theme file, then the function is not called.
I did a search for this function in the Drupal 8 standard installation and it only ever seems to be called from modules. Can hook_page_attachments only be called from modules? Any suggestions on why this is not working.
mytheme.theme file content:
function mytheme_page_attachments(array &$attachments) {
$attachments ['#attached']['library'][] = 'mytheme/general-js';
}