Skip to content

Instantly share code, notes, and snippets.

@mynameispj
Created June 20, 2012 15:30
Show Gist options
  • Save mynameispj/2960503 to your computer and use it in GitHub Desktop.
Save mynameispj/2960503 to your computer and use it in GitHub Desktop.
Drupal 7: add CSS files to certain nodes in template.php
function pj_preprocess_page(&$variables, $hook) {
//ADD TESTICULAR CANCER CSS TO FRONT PAGE
if (drupal_is_front_page()) {
drupal_add_css(drupal_get_path('theme', 'pj') . '/css/tc.css', array('group' => CSS_THEME, 'type' => 'file'));
}
// When this goes through the theme.inc some where it changes _ to - so the tpl name is actually page--type-typename.tpl
if (isset($variables['node'])) {
$variables['theme_hook_suggestions'][] = 'page__type__'. str_replace('_', '--', $variables['node']->type);
//ADD TESTICULAR CANCER CSS TO BLOG POST
if ($variables['node']->nid == 24) {
drupal_add_css(drupal_get_path('theme', 'pj') . '/css/tc.css', array('group' => CSS_THEME, 'type' => 'file'));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment