5

假设我有这个实现hook_menu()

function example_menu(){
    $items = array();

    $items['admin/recent-completions'] = array(
        'title' => 'Recent Completions (Last 100)',
        'page callback' => 'example_recent',
        'access callback' => user_access('Administer content'),
        'type' => MENU_NORMAL_ITEM,
        'weight' => -50
    );

    return $items;
}

如何为页面回调制作模板而不是返回字符串?

4

2 回答 2

5

您需要实现一个hook_theme函数并指定一个模板文件。

然后在你的页面回调中,你必须调用你的主题函数。就像是...

function example_theme($existing, $type, $theme, $path) {
  return array(
    'recent_completion' => array(
      'render element' => 'elements', 
      'template' => 'recent-completions',
    ), 
  ...
}

function example_recent() {
  // Do some logic and processing here
  $render_array = array( /* array with parameters for the template */ );
  return theme('recent_completion', $render_array);
}
于 2011-10-10T14:55:51.770 回答
0

我有同样的问题,但不确定如何实现 hook_theme 函数。就是它的完成方式(至少在 Drupal 6 中)。

于 2012-04-15T17:31:37.243 回答