-
-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".
-
------
-Checking if the function block_class() exists before calling it
------
-
-If there's a chance you may disable the Block Class module, you should consider placing the PHP snippet inside a conditional statement that checks to make sure the function actually exists before calling it: . This will prevent a nasty "Call to undefined function" error.
-
-Why use function_exists() instead of Drupal's handy module_exists() function? It's faster!
-
-
-=====
-Method 2: Using the $block_classes variable and template_preprocess_block()
------
-Step 1
------
-Add this snippet to your theme's block.tpl.php inside the block's class definition:
+4. Add this snippet to your theme's block.tpl.php inside the block's class definition:
@@ -58,24 +24,4 @@
-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".
-
------
-Step 2
------
-Modify your theme's template.php to include an implementation of template_preprocess_block(). This preprocess function should define the variable $block_classes. Here's an example:
-
-/**
- * Implementation of template_preprocess_block().
- *
- * The following is an example of how to automatically add classes to your
- * blocks by adding a $block_classes variable to to block.tpl.php
- */
-function YOURTHEME_preprocess_block(&$variables) {
- if (isset($variables['block_class'])) {
- $variables['block_classes'] .= ' '. block_class($block);
- }
- else {
- $variables['block_classes'] = block_class($block);
- }
-}
+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".
\ No newline at end of file
Index: block_class.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/block_class/block_class.module,v
retrieving revision 1.3.4.3
diff -u -r1.3.4.3 block_class.module
--- block_class.module 3 Jun 2009 12:46:41 -0000 1.3.4.3
+++ block_class.module 1 Oct 2009 11:23:52 -0000
@@ -58,3 +58,15 @@
$attributes = block_class_attributes($block);
return $attributes->css_class;
}
+
+/**
+ * Preprocess block templates. Add $block_classes variable to block.tpl.php template.
+ */
+function block_class_preprocess_block(&$variables) {
+ if (isset($variables['block_class'])) {
+ $variables['block_classes'] .= ' '. block_class($variables['block']);
+ }
+ else {
+ $variables['block_classes'] = block_class($variables['block']);
+ }
+}
\ No newline at end of file