开发者

While converting a Drupal 6 theme to Drupal 7, is there a work-around for theme_blocks()?

开发者 https://www.devze.com 2023-03-30 15:54 出处:网络
I currently use开发者_如何学运维 theme_blocks() in a base theme for Drupal 6, and I have had difficulty converting my theme to Drupal 7 because theme_blocks() is not used in Drupal 7. The below code i

I currently use开发者_如何学运维 theme_blocks() in a base theme for Drupal 6, and I have had difficulty converting my theme to Drupal 7 because theme_blocks() is not used in Drupal 7. The below code is a simple implementation of the function and how I currently use it in Drupal 6:

/* Implementation of theme_blocks() */
function theme_blocks($region) {
  var output = '';
  if ($list = block_list($region)) {
    //cycle through all blocks in a region
    foreach ($list as $key => $block) {
      //test each block for a given condition
      if ($block->delta == 1) {
        output = /* make some changes */
      }
      else {
        output = /* theme per usual */
      }
    }
  }

  return $output;
}

So, essentially I was just using theme_blocks() to cycle through all blocks in a region, targeting a specific block, and change up a few things. The problem is that theme_blocks() is not anymore used in Drupal 7.

Is there a way to target specific block/blocks in a given region, and dynamically make changes based on a theme setting in Drupal 7?


The theme_blocks() theme function (it is not a hook) is not used anymore in Drupal 7. If you need to alter how a block is rendered you need to implement a preprocess function for the block template file (THEMENAME_preprocess_block(); see the documentation for template_preprocess_block()) or use the block.tpl.php template file in your theme.

Keep in mind that the logic part should go in the preprocess function, and the rendering code should go in the template file.

0

精彩评论

暂无评论...
验证码 换一张
取 消