drupal 6:如何从自定义模块获取数据到模板文件 [英] drupal 6: how to get data from a custom module in to a template file
问题描述
我使用自定义模块在example.com/frontpage创建我的主页的内容。
im using a custom module to create the contents of my homepage at example.com/frontpage.
在模块中,我运行一个查询,获取我需要的数据,在一个数组中。当我返回主题('page',$ my_array)时,我得到了主页的主页,即默认drupal标志和站点名称在主要内容区域再次显示。
in the module i run a query that gets the data i need, in an array. when i return theme('page', $my_array) i get the "homepage inside the homepage", ie the default drupal logo and sitename is displayed a second time in the main content area.
最好的方法是创建一个特定的tpl.php文件,其内容应该是...?
what's the best way to go about this, create a specific tpl.php file, the contents of which should be ... ?
我意识到一个非常一般的问题,但在2个小时的尝试中,阅读教程完全不是很远。
i realise its a very general question but in 2 hours of trying things out and reading tutorials ive gotten not very far at all ...
谢谢
推荐答案
如果我正确地理解你的问题,所有你需要做的就是返回内容而不通过 theme_page
。 theme_page
将您的内容包装在网站模板中,因此在您的案例中手动调用它是复制模板。
If I'm understanding your question correctly, all you have to do is return the content without running it through theme_page
. theme_page
takes your content and wraps it in the site template, so calling it manually in your case is duplicating the template.
另一个解决方案是使您的页面的回调函数不返回任何内容,而不是打印 theme_page
的输出。如果回调函数不返回文本,则不会自动包含该网站的模板。
An alternate solution is to have your page's callback function not return anything, instead printing the output of theme_page
. If a callback function returns no text, the site's template is not included automatically.
<?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;
}
这篇关于drupal 6:如何从自定义模块获取数据到模板文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!