Remove stylesheet selectively in Drupal for page

人盡茶涼 提交于 2019-12-06 04:38:53

问题


I am trying to make different layout for the front page. In that process I declared new stylesheet called "front-page.css" and page--front.tpl.php. I am using a Zen subtheme which loads responsive-sidebar.css. I want to remove "responsive-sidebar.css" and load "front-page.css". The reason I am doing it because the number of grind columns in the later stylesheet is different that former.

I don't want to use Panels module. I am using Drupal 7.


回答1:


The Drupal 7 way is to use hook_css_alter():

function MYMODULE_css_alter(&$css) {
  // Remove defaults.css file. The path will probably change for your theme obviously.
  unset($css[drupal_get_path('theme', 'MYTHEME') . '/css/responsive-sidebar.css']);
}

That hook can be implemented in either a module or a theme.




回答2:


Inside your theme's template.php file and inside the template_preprocess_page($vars), find the CSS file you want to remove inside $vars['stylesheets'] and use PHP's unset function to remove it from the $vars['stylesheets'] array.




回答3:


I just found better way to do this. It is bit hacky, but allows to unset css at almost any place:

$css = &drupal_static('drupal_add_css', array());
unset($css['some_css_path']);


来源:https://stackoverflow.com/questions/14121231/remove-stylesheet-selectively-in-drupal-for-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!