skype

LiveZilla Live Help

Login



Blog
Comments
Home : Blog : CMS - Content Management Systems : How to assign custom CSS class for individual block in Drupal

How to assign custom CSS class for individual block in Drupal

E-mail
User Rating: / 3
PoorBest 
CMS - Content Management Systems
Thursday, 15 April 2010 10:56
This might be usefull for anyone who wants to improve their Drupal theme. By default it is really hard to assign the class or id to individual blocks.

The solution is here

http://drupal.org/project/block_class

This is a great module, when you enable it you can see a special box under each block, where you can add a name of that class. But you neeed to overrode the default block.tpl file.

Add this snippet to your theme's block.tpl.php file (see detailed instructions below):

Here is a sample of my code in block.tpl file

<?php
// $Id: block.tpl.php,v 1.3 2007/08/07 08:39:36 goba Exp $
?>
<div id="block-module; ?>-delta; ?> ">
<h2><?php print $block->subject; ?></h2>
<div><?php print $block->content; ?></div>
</div>


As you can see this snipet

<?php print block_class($block); ?>

is adding css to the code.

p.s. 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.
Comments
Add New Search RSS
+/-
Write comment
Name:
Email:
 
Title:
 
Please input the anti-spam code that you can read in the image.