3.2. Creating Your Own Block Theme Templates

Important! The Block Theme Module is not currently available for Drupal version 6. Therefore, the Block Theme Templates are not currently included in Tapestry for Drupal 6.

A Block Theme Template is simply a variation of the standard block.tpl.php file that Drupal uses to style blocks. The simplest Block Theme Templates might do nothing more than assign a unique CSS class to the block so that it can be styled using CSS. A more complex template might include background images, rollover effects, and other treatments.

The default block.tpl.php file used by Tapestry looks like this:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" 
class="block block-<?php print $block->module ?> unstyled-block">

<?php if ($block->subject): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif;?>

  <div class="content"><?php print $block->content ?></div>
</div>

Tapestry includes several Block Theme templates that differ from this default file only in that they assign a unique CSS class name to the block. For example, here's a look at the blk-solid1.tpl.php template file:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" 
class="block block-<?php print $block->module ?> blk-solid blk-solid1">

<?php if ($block->subject): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif;?>

  <div class="content"><?php print $block->content ?></div>
</div>

Notice that the only difference between the two files is the assigned class names (highlighted in red.) If you take a look in the style.css file, you will find the following CSS code:

.blk-solid { margin: 5px; padding: 5px; }

Additionally, the individual CSS files for each individual color style will further define the block theme template. For example, the file gerberdaisy.css includes the following CSS code:

.blk-solid1 { background: #EABE10;  color:#fff; }
.blk-solid1 a { color:#9A8C80; }

The remaining block theme templates are similarly 'wired' to the style.css file for basic formatting, and to the individual color style CSS files for specific color styling.

To create your own block theme templates, duplicate either the default block.tpl.php file or an existing block theme template file. Rename the file, being sure to end the filename with .tpl.php. Modify the class name assignments in the template to reference a unique class name. And then add the necessary CSS code to style.css and to the CSS file for the color style you are using, being sure to match the CSS class name to the one you used in the template file.

Before you can use your new block theme template, you'll need to add it to the list of available templates on the Block Theme Settings page.