Skip to content

Instantly share code, notes, and snippets.

@chrisl8888
Created November 19, 2012 21:41
Show Gist options
  • Select an option

  • Save chrisl8888/4114195 to your computer and use it in GitHub Desktop.

Select an option

Save chrisl8888/4114195 to your computer and use it in GitHub Desktop.
drupal 7: adding classes to blocks with preprocessing. borrowed from http://www.webbykat.com/2012/09/adding-class-block-drupal-7-block-class-module-vs-preprocessing
<?php
/**
* Selectively add classes to certain blocks
*
* Implements alpha_preprocess_block
*/
function sil_alpha_preprocess_block(&$var) {
$block_id = $var['block']->module . '-' . $var['block']->delta;
$classes = &$var['attributes_array']['class'];
switch ($block_id) {
/* Add .badge class to block #14 */
case 'block-14':
$classes[] = 'badge';
break;
/* Add .form class to block #20 */
case 'block-20':
$classes[] = 'form';
break;
default:
// Print out block id's
// var_dump($block_id);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment