Created
December 19, 2012 15:27
-
-
Save carwin/4337491 to your computer and use it in GitHub Desktop.
Create a body class for a specific node type based on the value of a field on the node.
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
<? | |
function themename_preprocess_html(&$variables) { | |
// Add a body class to Articles based on the value of the 'field_article_type' | |
// field. e.g.: 'article-type-news' or 'article-type-blog'. | |
if(!empty($variables['page']['content']) && !empty($variables['page']['content']['system_main']['content']['nodes'])) { | |
$node = $variables['page']['content']['system_main']['content']['nodes'][arg(1)]['body']['#object']; | |
if(user_is_logged_in()) { | |
$node = $variables['page']['content']['system_main']['content']['nodes'][arg(1)]['#node']; | |
} | |
if($node->type == 'article' && !empty($node->field_article_type)) { | |
$type = field_get_items('node', $node, 'field_article_type'); | |
$type_value = field_view_value('node', $node, 'field_article_type', $type[0]); | |
$variables['classes_array'][] = 'article-type-' . strtolower(render($type_value)); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment