Drupal Block Refresh module caveats

Drupal

There is an issue with the Block Refresh module.

After installation and configuration I discovered that the auto refresh was not working. Firefox's Firebug extension showed that requests were made at the proper interval and data was actually returned, but the block's content was simply not being updated.

When in doubt, one of the things you should do is enable a Drupal default theme to exclude any issues with custom code and CSS. It worked in Garland, for example.

I used a simple test block displaying the time stamp in the body and set the interval to, say, 10 seconds:

<?php
print 'Time stamp at last update was: ';
print
format_date(time(),'custom','H:i:s');
?>

With Firebug I compared the block code from Garland to mine. Garland returned:

<?php
<div class="block block-block" id="block-block-16">
  <
div class="content">
   
Time stamp at last update was: 10:47:28
 
</div>
</
div>
?>

While my theme returned:

<?php
<div class="defaultblock">
  <
h2>Auto refresh test</h2>
  <
div class="blockcontent">
   
Time stamp at last update was: 10:47:42
 
</div>
</
div>
?>

A Drupal forum topic listed the block ID as a possible cause. Indeed, I was not using an ID at all. But after adding the ID, it still didn't work.

Apart from the block ID, Garland uses a class of content and I was using blockcontent. Simply adding the block ID and the content class and it all started working:

<?php
<div id="block-<?php print $block->module . '-' . $block->delta; ?>
" class="defaultblock">
  <h2><?php print $block->subject; ?></h2>
  <div class="blockcontent content">
    <?php print $block->content; ?>
  </div>
</div>
?>

Which becomes:

<?php
<div class="defaultblock" id="block-block-16">
  <
h2>Auto refresh test</h2>
  <
div class="blockcontent content">
   
Time stamp at last update was: 10:52:45
 
</div>
</
div>
?>

In summary, there are several things you need to do:

  • Enable the module (of course).
  • Set the permissions for the block_refresh.
  • Ensure you are using a block ID of:
    <div id="block-<?php print $block->module .'-'. $block->delta; ?>">

  • Ensure you are using a block content class of:
    <div class="content">

These issues are not documented in the README of the module.

Update for Drupal 7.x

For Drupal 7 the same advice holds true. The default themes use the block template from the block module, where the block ID is created with print $block_html_id, which already converts underscores into hyphens:

<?php
<div id="<?php print $block_html_id; ?>
" class="<?php print $classes;?>"<?php print $attributes; ?>>
?>

The variable $block_html_id is defined in template_preprocess_block() function:

<?php
 
// Create a valid HTML ID and make sure it is unique.
 
$variables['block_html_id'] = drupal_html_id('block-' . $variables['block']->module . '-' . $variables['block']->delta);
?>

The function drupal_html_id() in common.inc converts all underscores in the ID to hyphens:

<?php
$id
= strtr(drupal_strtolower($id), array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
?>

And that's what we need for block refresh to function.