So I have a custom layout plugin and it's working just fine
I would like to add some conditional stylesheets for IE that are only added when this layout is used
It would make sense to have these as part of the layout, possible?

Comments

merlinofchaos’s picture

Category: support » feature

Oh that's an interesting question. Drupal 7 has the ability to make stylesheets conditional where Drupal 6 did not, but layouts have not yet been updated to handle this kind of functionality.

The simplest way to get this would be to add your stylesheets during the preprocess for your layout's template. But it sure would be nice if we could have it directly in the layout's .inc file.

Changing to feature request. This needs some research but theoretically should not be hard.

MustangGB’s picture

Fantastic!
I shall use preprocess for now, but as you said, it would be nice if these could be handled.
As this would then keep relevant "code" all in one place.

EDIT:
For anyone interested here is the preprocess code I added.

function THEME_preprocess_node(&$variables, $hook) {
  // Optionally, run node-type-specific preprocess functions, like
  // THEME_preprocess_node_page() or THEME_preprocess_node_story().
  $function = __FUNCTION__ . '_' . $variables['node']->type;
  if (function_exists($function)) {
    $function($variables, $hook);
  }
}

function THEME_preprocess_node_panel(&$variables, $hook) {
  $display = panels_load_display($variables['panels_node']['did']);
  $layout = panels_get_layout($display->layout);
  $data = $layout['path'] . '/' . $layout['name'] . '-ie.css';
  $options = array(
    'browsers' => array(
      '!IE' => FALSE,
    ),
  );
  drupal_add_css($data, $options);
}
gmclelland’s picture

Version: 7.x-3.0-alpha3 » 7.x-3.x-dev

I think this could be a handy feature especially now that SASS based CSS grid frameworks have the capability to export media query specific ie only stylesheets. For example, you don't want to include IE6-IE7 media query styles in your standard stylesheets to reduce the page weight.

If interested here are some SASS libraries/frameworks that can do this:
https://github.com/canarymason/breakpoint see https://github.com/canarymason/breakpoint#no-query-fallback
http://susy.oddbird.net/ http://susy.oddbird.net/guides/reference/#ref-compass-options
http://zengrids.com/ http://zengrids.com/help/#vars-legacy