When I enable block caching, the earth_hour.css file is included in the first page request. But when I refresh the page the css file is left off and the message is displayed without css.

I moved the css definition from the earth_hour_block function to the earth_hour_init() function:

function earth_hour_init() {
  earth_hour_check_time();
  drupal_add_css(drupal_get_path('module', 'earth_hour') .'/earth_hour.css');
}

That seemed to fix it.

Comments

mgifford’s picture

That would have the earth_hour.css file loaded all year around. Now it could well be tied to block caching.

earth_hour_block_view() shouldn't be cached according to earth_hour_block_info().

drupal_add_css(drupal_get_path('module', 'earth_hour') .'/earth_hour.css'); isn't loaded (as it's cached).

d6: http://www.churchillnews.ca
d7: http://openconcept.ca

I'm still looking at this, but it seems like a D7 function snuck into D6:

/**
 * Implementation of hook_block_info().
 */
function earth_hour_block_info() {
  // This example comes from node.module.
  $blocks['earth_hour'] = array(
    'info' => t('Earth Hour'),
    //     $blocks[0]['description'] = t('The Earth Hour block allows you to show your support for Earth Hour on your site.');
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

This is just for the top bar on the page.