Skip to content

Instantly share code, notes, and snippets.

@cam8001
Created December 11, 2012 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cam8001/4258295 to your computer and use it in GitHub Desktop.
Save cam8001/4258295 to your computer and use it in GitHub Desktop.
Using preprocess_html to add custom classes to the HTML tag. Add to a file called template.php in the 'nes' theme.
<?php
/**
* Implements hook_preprocess_html().
*/
function nes_preprocess_html(&$variables) {
// Add some special classes to the HTML tag, so that we can style on a per-view basis.
// Get the current function handling the page.
$variables['menu_item'] = menu_get_item();
// If it is a views.module provided page, add some classes to the html tag.
if ($variables['menu_item']['page_callback'] == 'views_page') {
// First, add a general class.
$class = 'page-views';
$variables['classes_array'][] = $class;
// Then, for each argument to the view (like view name), add a specific class.
foreach ($variables['menu_item']['page_arguments'] as $argument) {
$class .= '-' . $argument;
$variables['classes_array'][] = $class;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment