I have created a block using Views module in website using drupal 7. My block title's HTML structure is as bellow:

<div class="titleHeader clearfix">

I want to add a class in <div>. Should I create a module for this or any other way? Please guide me how can I do this?

Thank you in advance

  • You should first search in Google then post somewhere.
    – AgA
    Sep 17, 2013 at 9:07
  • Yes I had and found a way by using module. But it doesn't worked for me. Sep 17, 2013 at 9:09

3 Answers 3


function themename_preprocess_block(&$variables) {

if($variables['block']->bid == 'views-front-block') {

     $variables['classes_array'][] = 'container';


add this function in your template.php file of your theme.


Your view -> Edit -> Expand Advanced Fieldset -> Theme: Information. Copy the template suggestion from Style output (Display output? I can't really remember) container and create that file (Do not forget to clean the cache). Then copy the default code and modify it. For ex.:

<?php print $wrapper_prefix; ?>
  <?php if (!empty($title)) : ?>
    <div class="myClass"><h3><span><?php print $title; ?></span></h3></div>
  <?php endif; ?>
  <?php print $list_type_prefix; ?>
    <?php foreach ($rows as $id => $row): ?>
      <li class="<?php print $classes_array[$id]; ?>"><?php print $row; ?></li>
    <?php endforeach; ?>
  <?php print $list_type_suffix; ?>
<?php print $wrapper_suffix; ?>

I think the Block Class module will allow you to add classes in blocks. Here is a quote about it (from the module's project page):

... allows users to add classes to any block through the block's configuration interface. By adding a very short snippet of PHP to a theme's block.tpl.php file, classes can be added to the parent <div class="block ..."> element of a block. Hooray for more powerful block theming!

  • It just add class in <div> of block. I want to add class in <div> for title of the block. Sep 17, 2013 at 9:08
  • You can use sibling selector in CSS to do so( css-tricks.com/child-and-sibling-selectors)
    – AgA
    Sep 17, 2013 at 9:16
  • I want to add bootstrap.css class in this <div> so it will not work. Sep 17, 2013 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.