我有一个自定义模块,可以从 Web 服务调用返回数据。它来自 XML 响应,我将其转换为数组。
一旦我有了数组,我就会:
$output = theme('search_srs_results', $data);
return $output;
但是我遇到了白屏。没有 apache/php/watchdog 错误。
我之前曾在另一个模块中毫无困难地完成过此操作。我的主题 Hook 已定义,并指向模板文件,传递 $data 参数。如果我在 $output 返回之前将其转储,则其为 NULL。
$data 在主题化之前肯定有一个填充数组。
如果我执行 theme('item_list', $data);,它会呈现,没有白屏。
我尝试再次阅读有关 hook_theme 和 theme() 的文档,但我似乎没有做任何错误。
以下是主题功能:
/**
* Implementation of hook_theme()
*/
function srs_finder_theme() {
return array(
'search_srs_results' => array(
'template' => 'srs-finder-results',
'arguments' => array('data' => null),
),
);
}
/**
* Implementation of hook_preprocess()
*/
function srs_finder_preprocess_search_srs_results(&$vars) {
$data = $vars['data'];
}
缺少什么?
最佳答案
我根本不明白为什么你需要 hook_preprocess()
函数。 $data
应自动可供 srs-finder-results.tpl.php
使用。那是因为您在调用 theme('src_src_results', $data)
中传递此变量,并且您已声明 hook_theme()
中有 1 个参数。
srs-finder-results.tpl.php
文件应驻留在 src_finder
模块文件夹中。您需要为此实现代码! (或者,正如 nikit 上面评论的那样,提供一个 theme_search_srs_results
函数。在这种情况下,您将需要删除 template
数组条目)
[注意:如果模块的其他用户想要覆盖此主题模板,他们始终可以在主题的主题文件夹中提供自己的 srs-finder-results.tpl.php
实现,处于事件状态。]
关于Drupal theme() 函数和自定义模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4056497/