我遇到了一个我无法解决的小问题。我有一个网站,会有一组页面,这些页面将是定制的(但有页面的模板),只有定制的内容。
例如:http://mypage.com/?q=stuff
我读过关于挂钩的文章,并制作了文件page--stuff.tpl.php和重复的page.tpl.php,但页面标题是-找不到页面,我做得不对,因为复制了page.tpl.php
这些页面将包括自定义的手写模块和自定义的PHP代码,但总体布局将与其他节点相同。
我怎么能做到这一点?
要创建一个没有链接到节点的页面,必须在自制模块中实现hook_menu。
function MODULENAME_menu() {
return array("stuff" => array( // link (in your case: http://mypage.com/stuff)
'title' => "stuff", // title of the page
'page callback' => "themefunction", // logic for the content
'type' => MENU_CALLBACK // there are more types, read hoo_menu() for further details
);
}
您可以用任何您喜欢的东西替换themefunction,但您必须实现它!
function themefunction() {
// do some theming output stuff like:
$items['hello'] = "Hello World!"; // your variable output
return theme('stuff_theme', array('items' => $items)); // say Drupal to theme that stuff in your default page-template
}
然后,您需要通过实现hook_theme(在您的主模块文件中也是don)在Drupal中注册您的主题
function MODULENAME_menu() {
return array(
'stuff_theme' => array( // file name of the template WITHOUT .tpl.php
'variables' => array(
'items' => NULL // variables that are assigned to the template
)
)
);
}
最后,您需要创建模板*stuff_theme.tpl.php*(在模块文件夹中):
<div><?= $items['hello']; ?></div>
不幸的是,这是创建真正自定义内容页面的唯一方法。对于节点中的小代码注入,您还可以启用PHP过滤器模块。