Monday, 9 March 2015

Block Class

  1. Install this module from the url : https://www.drupal.org/project/block_class
  2. Enable this module
  3. Go into page 'admin/structure/block' and click 'configure' of which block you want to add classes to
  4. The configuration page for the block shows up and set up the classes in the input of 'CSS classes'. 
  5. Create a block template file for this specific view referring to drupal template suggestions. For example: block--views--whats-new-whats-new-block.tpl is for the block with the machine name 'whats-new' which can be easily found by 'theme developer'
  6. Copy the code of block.tpl.php into the specific block template file which created at step 5
    <div id="<?php print $block_html_id; ?>" class="<?php print $classes; ?>"<?php print $attributes; ?>>
      <?php print render($title_prefix); ?>
      <?php if ($title): ?>
        <h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
      <?php print $content; ?>
    </div><!-- /.block -->

  7. Tweak the first line of the step 6 code by adding 'print $block_classes' snippet
    <div id="<?php print $block_html_id; ?>" class="<?php print $classes . ' ' . $block_classes; ?>"<?php print $attributes; ?>>
      <?php print render($title_prefix); ?>
      <?php if ($title): ?>
        <h2<?php print $title_attributes; ?>><?php print $title; ?></h2>
      <?php endif; ?>
      <?php print render($title_suffix); ?>
      <?php print $content; ?>
    </div><!-- /.block -->

No comments:

Post a Comment