drupal区块,内容和它们的区域

      主题中可用的区块区域是在.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的区块管理页面 :

Garland block configuration example

一些注意点:

  • 每个单独区块的显示都可以使用模板文件
  • 添加一个定制区域,就会阻止使用默认的.如果你想继续保留这些默认的区域,你需要手工的将其添加进去.
  • 区域的定义顺序将反映到区块配置页面. 例如Garland使用的为默认区域.注意图中区域的顺序.
  • .info文件中的内容被缓存了。所以对它的修改都不会显示出来。(不要将它与主题注册表混淆了。)为了清空缓存,你可以这样:

    1. 点击位于"Administer > Site configuration > Performance"的清空(Clear)按钮
    2. 如果启用了devel区块的话(devel模块生成的),点击链接"Empty cache"。
    3. 简单的访问主题选择页面"Administer > Site building > Themes"

升级提示:

原文:http://drupal.org/node/171224

译者:葛红儒, Think in Drupal

  • 在Drupal 5以及更低版本中,是使用ThemeName_regions() 或EngineName_regions()声明区域的.而在Drupal6中,这两个方法已不再被推荐使用.
  • 如果你要将你的主题从以前的版本升级到Drupal6,其中用到$sidebar_left 和$sidebar_right的话,需要将其改名为$left and $right.
  • 在以前的版本中, $footer_message区域变量是将页脚区域(footer region)和页脚消息(footer message)混到了一起.(在"Administer > Site configuration > Site information"中设置).而在Drupal6中,这两个变量是分开的,所以你需要单独创建一个$footer变量.

Drupal版本:

手工的将内容指派给特定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

Drupal版本: