在Drupal中有选择地删除样式表以获取页面

问题描述 投票:4回答:3

我正在尝试为首页制作不同的布局。在那个过程中,我声明了名为“front-page.css”的新样式表和page - front.tpl.php。我正在使用一个Zen subtheme来加载responsive-sidebar.css。我想删除“responsive-sidebar.css”并加载“front-page.css”。我这样做的原因是因为后面样式表中的研磨列数与前者不同。

我不想使用Panels模块。我正在使用Drupal 7。

php drupal drupal-7 drupal-theming drupal-zen
3个回答
2
投票

Drupal 7方式是使用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']);
}

该钩子可以在模块或主题中实现。


2
投票

在你的主题template.php文件和template_preprocess_page($vars)里面,找到你要在$vars['stylesheets']中删除的CSS文件,并使用PHP的unset函数将其从$vars['stylesheets']数组中删除。


0
投票

我刚刚找到了更好的方法来做到这一点。它有点hacky,但允许在几乎任何地方取消设置css:

$css = &drupal_static('drupal_add_css', array());
unset($css['some_css_path']);
© www.soinside.com 2019 - 2024. All rights reserved.