主题中可用的区块区域是在.info文件中定义的。定义方式为键'regions'+[],[]之间为内部名称,再加“=”,最后跟上外部名称,例如regions[theRegion] = The region label。如果没有定义的话,将会使用下面的默认值。
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
记住,内部名称将自动转化为"page.tpl.php"模板中的区域变量。在前面的例子中,[left]区域将通过$left变量输出所有指定给该区域的区块。PHP变量的命名存在一些限制,所以区域的内部名称也要遵守相同的约束。它只能包含字母数字字符,以及下划线,注意数字不能放 在开始位置。
方括号外面的外部名称,是用在区块管理面的,用来标记区域名,"Administer > Site building > Blocks"。
下面是Garland的区块管理页面 :
一些注意点:
升级提示:
原文:http://drupal.org/node/171224
译者:葛红儒, Think in Drupal
使用drupal_set_content可以将内容手工的添加到区域中.例如, drupal_set_content('header', 'Welcome!')将文本'Welcome!'添加到页首区域.下面是一个更有用的例子,构建所有评论的总结并将其放到"right"区域.
将前缀"drop"改为你主题的名字.更多信息参看预处理器
<?php
function drop_preprocess_comment(&$variables) {
// Setup a few variables.
$comment = $variables['comment'];
$title = l(
$comment->subject,
comment_node_url(),
array('fragment' => "comment-$comment->cid")
);
$new_marker = $comment->new ? t('new') : '';
$by_line = t('by') .' '. theme('username', $comment);
// Form the markup.
$summary = '<div class="comment-sidebar">';
$summary .= "<span class=\"title\">$title $new_marker</span>";
$summary .= "<span class=\"credit\">$by_line</span>";
$summary .= '</div>';
// Set the comment into the right region.
drupal_set_content('right', $summary);
}
?>
注意通过这个函数设置内容,发生在区块区域回显以前,它是这样调用的template_preprocess_page > theme_blocks > drupal_get_content.
原文:http://drupal.org/node/171224
译者:葛红儒, Think in Drupal