I have a base theme that loads several libraries, some through the libraries.yml file and some loaded conditionally in a preprocess function. I also have a base theme with its own library loaded through libraries.yml.
This is the order they are loading in:
- Libraries loaded in base theme's libraries.yml
- Libraries loaded in sub theme's libraries.yml
- Libraries loaded in base theme's preprocess function
This is a problem because I need to override some CSS from the libraries loaded in the base theme's preprocess function in my subtheme. I want it to load like this:
- Libraries loaded in base theme's libraries.yml
- Libraries loaded in base theme's preprocess function
- Libraries loaded in sub theme's libraries.yml
They are loading in that order regardless of the CSS weights defined in the libraries file (base, theme etc.).
Is there anything I can do about this? This is the relevant code from the base theme, used in hook_preprocess_html().
if (\Drupal::moduleHandler()->moduleExists('module')) {
$variables['#attached']['library'][] = 'basetheme/library';
}
Will libraries loaded through a preprocess function always load later than the libraries loaded through libraries.yml? Are there any resources that explain this? And as an aside, where would libraries loaded through twig go?