You are here

手工的将内容指派给特定drupal区域

g089h515r806 的头像
Submitted by g089h515r806 on 星期日, 2008-08-31 08:46

使用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版本: