Context Block Class gives users of the Context module the ability to define custom classes for blocks per context, both for each block and globally for a region. The module implements a context reaction, providing the interface required for adding classes to blocks which have been defined for that context. This unlocks a tremendous amount of theming flexibility for users of Context module. When combined with a grid based theme or any other theme which implements re-usable styles, the options are endless!

Requirements

Installation

  1. Enable the module.
  2. Ensure that your theme has a copy of block.tpl.php.
  3. Insert a PHP snippet to your theme's block.tpl.php file(s) that prints the $context_block_classes variable (see below).
  4. To add a class to a block or to all blocks within a region, add the "Block classes" reaction to your context.

Adding the php snippet

Add this snippet to your theme's block.tpl.php inside the block's class definition:

<?php
print $context_block_classes;
?>

Here's the first line of the Garland theme's block.tpl.php prior to adding the code:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?>">

And here's what the code should look like after adding the snippet:
<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?> <?php print $context_block_classes; ?>">

IMPORTANT: Remember to separate the PHP snippet from the existing markup with a single space. If you don't add the space, your CSS classes could run together like this: "block-modulecustomclass" instead of "block-module customclass".

Credits

Development of this module is sponsored by Advantage Labs, Inc.

This module pulls inspiration from the Block Class module. Developed by the fine folks at Four Kitchens.

Project Information

Downloads