1

I have a base theme and a sub-theme. The sub-theme specifies a single styles.css in the *.info file. The base theme provides CDN css stylesheets, via this hook:

function MYTHEME_preprocess_html(&$css) {

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/pure-min.css', array(
    'group' => CSS_THEME,
    'preprocess' => FALSE
  ));

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/grids-responsive-old-ie-min.css', array(
    'group' => CSS_THEME,
    'browsers' => array('IE' => 'lte IE 8'),
    'preprocess' => FALSE
  ));

  drupal_add_css('http://yui.yahooapis.com/pure/0.5.0/grids-responsive-min.css', array(
    'group' => CSS_THEME,
    'browsers' => array('IE' => 'gt IE 8'),
    'preprocess' => FALSE
  ));

  drupal_add_css('http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css', array(
    'group' => CSS_THEME,
    'preprocess' => FALSE
  ));  

}

The resulting HTML is this:

<style type="text/css" media="screen">@import url("http://mysite.local/sites/all/themes/mytheme/styles.css?nezret");</style>

<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css?nezret" media="all">

<link type="text/css" rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/grids-responsive-min.css?nezret" media="all">

I need the @import to come in dead last in rendered order -- otherwise it seems the base theme styles are overriding my theme specific styless...

I have tried to correct this in the sub--theme by doing:

  function MYTHEME_css_alter(&$css) {

    foreach($css as $key => $value) {
      if($key == 'sites/all/themes/MYTHEME/styles.css') {
        $css[$key]['weight'] = 1000;
      }
    }

    uasort($css, 'drupal_sort_weight');

  }

This fixes the array but not the rendering order...WTF am I missing or doing wrong???

2
  • What exactly generates the line you are seeing? If CDN module is messing with you and breaks your theme, it is a matter for bugreport rather than for question here. And please avoid things like "via CDN or otherwise". Be specific. If it's about CDN, ask about CDN. We can't really tell you what will work in unspecified situation. Not with any degree of certainty.
    – Mołot
    Nov 13, 2014 at 19:48
  • the order in which styles are being output is the question here...the styles.css I specify in theme.info I expect to render last to override the base theme...it is not...it appears before the <link> generated by base theme -- so base theme overrides anything in styles.css Nov 13, 2014 at 19:54

1 Answer 1

0

I would be curious to hear a alternative solution but this works too (albeit hackish):

I removed the reference to the stylesheet in *.info and simply added the call inside template.php:

function MYTHEME_preprocess_html(&$vars) {
    drupal_add_css(path_to_theme().'/styles.css', array(
      'group' => CSS_THEME, 
      'preprocess' => 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.