假设我有 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;
}
如何为页面回调制作模板而不是返回字符串?
最佳答案
您需要实现 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);
}
关于drupal - 为页面创建模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7713220/