1

Im working on a custom module which loads a CSS file:

$content['#attached']['css'] = array(
  path_to_theme() . '/new.css',
);

How can I change the weight of the file so that its loaded after the other CSS files? I thought it would be something like this:

$content['#attached']['css'] = array(
  path_to_theme() . '/new.css',
  'weight' => 1000,
);

Or this:

$content['#attached']['css'] = array(
  path_to_theme() . '/new.css',
  '#weight' => 1000,
);
6
  • May I ask why would you do that? Commented Jan 28, 2016 at 12:47
  • As its a custom module it has some custom styles that I would like loaded after the base styles of my theme. Eg if my theme has a class of button and this module's style has a class of button--large, then I need button--large to be loaded after button.
    – Evanss
    Commented Jan 28, 2016 at 12:49
  • it would be much easier to override base styles with ´! important´ I think Commented Jan 28, 2016 at 12:51
  • @Benone_ Nope, if you see !important in CSS, 99% of the time it means the developer wasn't quite sure what they were doing
    – Clive
    Commented Jan 28, 2016 at 12:57
  • @Clive with proper selector it would not do any unwanted changes Commented Jan 28, 2016 at 13:01

1 Answer 1

0

You want something more like this:

$content['#attached']['css'] = array(
  array(
    'data' => path_to_theme() . '/new.css',
    'type' => 'file', 
    'weight' => 1000,
  ),
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.