2

In D7 it's possible to attach a css file based on browser sniffing, like this:

drupal_add_css(
  $path_to_css,
  array(
    'browsers' => array(
      'IE' => 'lte IE 9',
      '!IE' => FALSE
    )
  )
);

Drupal 8 does away with drupal_add_css in favour of #attached => array('css' => array( $path_to_css )) but how, in that situation, can you achieve the same thing.

(Nb. I'm not actually using D8 yet, but where things can be done the D8 way in D7, I'm adopting them to ease the learning curve to come!)

2

I think this'll do it in Drupal 7, it should be the same for Drupal 8:

$build['#attached']['css'][] = array(
  'type' => 'file',
  'data' => $path_to_css,
  'options' => array(
    'browsers' => array(
      'IE' => 'lte IE 9',
      '!IE' => FALSE,
    ),
  ),
 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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