老葛的Drupal培训班 Think in Drupal
在一个页面请求周期内,主题系统向区块系统请求返回每个区域内的一列区块。当为页面模板文件(通常为page.tpl.php)变量赋值时,完成这一步骤。对于每个区域(比如,页脚区域),为了聚集主题化的区块,Drupal执行以下类似的代码:
$variables['footer'] = theme('blocks', 'footer');
你可能还记得第8章里面的theme(“block”),它实际上就是调用方法theme_blocks()。下面是theme_blocks()的代码:
/**
* Return a set of blocks available for the current user.
*
* @param $region
* Which set of blocks to retrieve.
* @return
* A string containing the themed blocks for this region.
*/
function theme_blocks($region) {
$output = '';
if ($list = block_list($region)) {
foreach ($list as $key => $block) {
$output .= theme('block', $block);
}
}
// Add any content assigned to this region through drupal_set_content() calls.
$output .= drupal_get_content($region);
return $output;
}
在前面的代码中,我们对每个给定区域中的区块进行迭代,并为每个区块执行一个主题函数调用,一般最终会调用block.tpl.php文件。有关主题化的原理,以及如何覆写单个区块的外观,参看第8章。最后,我们为调用代码返回该区域内所有主题化的区块。