I have a custom module that returns data from a web service call. It comes back from an XML response, which I am converting to an array.
Once I have the array, I do:
$output = theme('search_srs_results', $data);
return $output;
But I am getting a white screen. No apache/php/watchdog errors.
I've done this before in another module without any difficulty. My theme hook is defined, and points to a template file, passing the $data argument. If I dump $output before it's returned, its NULL.
$data definitely has a populated array before being themed.
If I do theme('item_list', $data);, it renders, no white screen.
I tried reading the docs again on hook_theme and theme() but I don't seem to be doing anything wrong.
Here are the theme functions:
/**
* 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'];
}
Whats missing?
Best Answer
I don't understand why you need
hook_preprocess()
function at all.$data
should automatically be available tosrs-finder-results.tpl.php
. Thats because you're passing this variable in the calltheme('src_src_results', $data)
and the fact that you have declared that there is 1 argument inhook_theme()
.srs-finder-results.tpl.php
file should reside in thesrc_finder
module folder. You need to implement the code for that! (Alternatively as nikit has commented above, provide atheme_search_srs_results
function. In that case you will need to remove thetemplate
array entry)[Note: If other users of the module want to override this theme template they can always provide their own implementation of
srs-finder-results.tpl.php
in the theme folder of the theme that is active.]