Last active
December 12, 2015 03:48
-
-
Save paulhhowells/4709275 to your computer and use it in GitHub Desktop.
Set a (whole) page’s background colour on a per node basis. A Drupal 7 theme function that adds a class to the body tag.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Implements template_preprocess_html | |
* | |
* requires: | |
* the content type to have a List[text] field called 'field_bg_colour' | |
* using Display Suite the field may be Hidden but not Disabled | |
*/ | |
function THEMENAME_preprocess_html(&$variables) { | |
// if a background colour has been set within the node, | |
// then set it as a class on the body tag | |
$node = menu_get_object(); | |
if (!empty($node)) { | |
$bg_colour = $node->field_bg_colour; | |
$items = field_get_items('node', $node, 'field_bg_colour', $node->language); | |
if (!empty($items)) { | |
$bg_colour_class = $items[0]['value']; | |
$variables['classes_array'][] = $bg_colour_class; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment