Created
May 23, 2012 16:05
-
-
Save pixelwhip/2776118 to your computer and use it in GitHub Desktop.
Drupal: Adding classes to blocks
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
<div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>> | |
<?php print render($title_prefix); ?> | |
<?php if ($block->subject): ?> | |
<h2<?php print $title_attributes; ?>><?php print $block->subject ?></h2> | |
<?php endif;?> | |
<?php print render($title_suffix); ?> | |
<div <?php print $content_attributes; ?>> | |
<?php print $content ?> | |
</div> | |
</div> |
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
<?php | |
/** | |
* Implements hook_preprocess_block() | |
*/ | |
function mytheme_preprocess_block(&$vars) { | |
/* Set shortcut variables. Hooray for less typing! */ | |
$block_id = $vars['block']->module . '-' . $vars['block']->delta; | |
$classes = &$vars['classes_array']; | |
$title_classes = &$vars['title_attributes_array']['class']; | |
$content_classes = &$vars['content_attributes_array']['class']; | |
/* Add global classes to all blocks */ | |
$title_classes[] = 'block-title'; | |
$content_classes[] = 'block-content'; | |
#print $block_id . '<br/>'; | |
/* Add classes based on the block delta. */ | |
switch ($block_id) { | |
/* System Navigation block */ | |
case 'system-navigation': | |
$classes[] = 'block-rounded'; | |
$title_classes[] = 'block-fancy-title'; | |
$content_classes[] = 'block-fancy-content'; | |
break; | |
/* Main Menu block */ | |
case 'system-main-menu': | |
/* User Login block */ | |
case 'user-login': | |
$title_classes[] = 'element-invisible'; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment