5

我想创建一个包含 page.tpl.php 中的 $tabs 的块

/**
 * Implements hook_block_info().
 */
function mymodule_block_info() {

  $blocks['tabs'] = array(
    'info' => t('Tabs in block'),
    'description' => t('blah blah blah'),
  );
  return $blocks;
}


/**
 * Implements hook_block_view().
 */
function mymodule_block_view($delta = '') {

  $block = array();

  switch ($delta) {

    case 'tabs':
      $block['subject'] = t("THIS IS ZHE TABS!");
      $block['content'] = array(
        '#theme' => 'menu_local_tasks',
        '#primary' => menu_local_tasks(0),
        '#secondary' => menu_local_tasks(1),
      );
    break;
  }
  return $block;
}



该块已正确注册,并且与呈现的选项卡一起正确显示。然而,Drupal 抛出了很多错误!

Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5777 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5815 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Cannot use a scalar value as an array in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5767 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5777 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#children' in drupal_render() (line 5815 of /Users/tolborg/Sites/bibdk/includes/common.inc).
Warning: Illegal string offset '#printed' in drupal_render() (line 5822 of /Users/tolborg/Sites/bibdk/includes/common.inc).
4

2 回答 2

0

似乎问题出在主题功能中,也许。

我尝试使用它并且它有效

$tabs =  menu_local_tasks(0);
$block['content'] =  $tabs['tabs']['output'];
于 2012-11-02T13:03:23.263 回答
0

有一个模块blockify可以完成这个任务并为你创建其他 page.tpl.php 元素。它还提供了要“阻止”哪些元素的管理页面

于 2015-04-16T17:18:47.273 回答