Hello
I'm programmatically creating a block in a module and simply want to add a css class to the block wrapper. There seems to be some advice on how manipulate block classes in template preprocess functions, but I just want to be able to set it where I create the block. Is this possible?
This is what I have at the moment
function tp_core_block_info() {
$blocks['myblock'] = array(
'info' => t('My Block'),
'cache' => DRUPAL_NO_CACHE,
);
}
function mymodule_core_block_view($delta = '') {
case 'myblock' :
$block['content'] = 'My Content';
break;
}
return $block;
}This produces a block with the following html wrapper
<div id="block-my-module-my-block" class="block my-block content-region block-my-block block-my-module-my-block odd block-without-title">
*rest of block html here*All I want to do is add a new class "no-background" to the class attribute at the time the block is created. I know this won't work, but I'm looking for something like this:
function tp_core_block_info() {
$blocks['myblock'] = array(
'info' => t('My Block'),
'cache' => DRUPAL_NO_CACHE,
'class' => 'no-background',
);
}The reason I want to do it this way is that for the most part, the blocks on my site will all have a white background, but in certain cases I want to turn this background off, so for these blocks I want to set a common css class that will disable it.
Is this possible?
I see that you can set a "properties" property in hook_block_info, but I don't see any information on what type of properties you can set or how.
Any help would be much appreciated!
Comments
You can use block_class
You can use block_class module to add the custom CSS class individually.
You can also use default generated class, because drupal generate classes based on block delta (key used in hook_block_info()).
-Imran