Community Documentation

Block.tpl.php

Last updated August 24, 2009. Created by joachim on October 21, 2004.
Edited by alexanderpas, Jeff Burnz, add1sun, Dublin Drupaller. Log in to edit this page.

Lays out content for blocks (left and/or right side of page). This template is optional, and can be overridden by copying the default template and modifying it.

Available variables

The $block object includes:

$block->module
The name of the module that generated the block.
$block->delta
The number of the block for a particular module.
$block->subject
The block title.
$block->content
The html content for the block.
$block->status
Status of block (0 or 1).
$block->region
Region name, by default the available regions are 'left', 'right', 'header' and 'footer'.
$block->throttle:
Throttle setting.

Other variables:

$directory
The directory the theme is located in, e.g. themes/garland or themes/garland/minelli.
$is_front
True if the front page is currently being displayed.
$id
The sequential id of the block displayed, ie: The first block is 1, the second block is 2 etc.
$block_id
The same as $id, but is reset for the left and right sidebars.
$zebra
Alternates between 'odd' and 'even'. This is useful for creating 'zebra stripes' with your css.
$block_zebra
The same as $zebra, but is reset for the left and right sidebars.

Default template

The default block.tpl.php, which can be found at themes/engines/phptemplate/block.tpl.php.

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

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

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

4.6 vs. 4.7 and higher

In 4.6 these variables are different:

  • $block->region only allows for Left (0), or Right(1) column.
  • Use $seqid instead of $id.
  • Use $block_seqid instead of $block_id.

In 4.7 and higher versions it is also possible to define custom regions in addition to the default 'left', 'right', 'header' and 'footer'.

Suggested reading:

Comments

This still comes up top on

This still comes up top on google for 'drupal block.tpl'
Is there a D6 version? I can't seem to find it.

Same thing for me

I was looking for a D6 block.tpl.php as well.

I would change the world, if God would give me the source code.

Drupal 6 block.tpl.php

Here is a default system block.tpl.php for Drupal 6:

http://api.drupal.org/api/drupal/modules--system--block.tpl.php/6

Click on the "View source" link for the code.