如果我正确理解你的问题,你所要做的就是返回内容而不通过theme_page
运行它。 theme_page
需要你的内容并将其包装在网站模板中,所以在你的案例中手动调用它是复制模板。
另一种解决方法是让你的页面的回调函数不返回任何东西,而不是打印的输出theme_page
。如果回调函数没有返回文本,则网站的模板不会自动包含。
<?php
function mymodule_menu() {
$items = array();
$items['option1'] = array(
'title' => 'Front page option #1',
'access arguments' => array('access content'),
'page callback' => 'mymodule_option1',
'type' => MENU_CALLBACK,
);
$items['option2'] = array(
'title' => 'Front page option #2',
'access arguments' => array('access content'),
'page callback' => 'mymodule_option2',
'type' => MENU_CALLBACK,
);
return $items;
}
function mymodule_option1() {
// build HTML content here
return $content;
}
function mymodule_option2() {
// build HTML content here
print theme('page', $content);
return null;
}
选项1工作,没有意识到var名称必须是$内容。现在我在我的主页上看到Array。所以我需要在mymodule_option1函数中构建完整的html?是不是你的意思是把PHP中的HTML不在PHP中的HTML? – stef 2009-08-12 14:27:46
选项2工作更好;谢谢ceejayoz! – stef 2009-08-12 14:32:19
如果你想使它成为真正的Drupalish,你应该制作一个主题函数,使得实际的HTML,而你的菜单回调做的逻辑。这是contrib模块可以覆盖它们的输出。但是,在一个自定义站点模块中,这个功能并不重要。除此之外,好的回应+1 – googletorp 2009-08-12 14:52:39