定义菜单回调函数 调用显示模板页面
自定义一个模板页面,通过菜单回调函数调用模板页面.定义一个.module文件,文件中写如下代码.
<?php
// Implementation of hook_menu.
function works_menu() {
$items['works'] = array(
'page callback' => 'works',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
// Implementation of hook_theme.
function works_theme() {
return array(
'works' => array(
'arguments' => array('element' => NULL),
'template' => 'template/works',
),
);
}
// Callback of 'works' menu item.
function works() {
return theme('works');
}
这时候需要定义模板,创建一个template文件夹(当然也可以不定义,可以直接把文件放在.module的同级目录下),在template中定义.tpl.php文件.定义一个works.tpl.php 可以在这里定义你的html结构代码,也可以调用其他函数例如一个form表单 . 如下是works.tpl.php中的代码
<p><span style="font-family: 'Arial';font-size: small;">Here’s the place to be listed if you can provide valuable training to Ohioans wishing to travel to foreign countries for academic, business, political or cultural exchange.</span></p>
<?php print drupal_get_form('works_information_form')?>
- 添加新评论
- 539 次点击