When you call theme('search_results', $results, 'node') from another module the preprocess function template_preprocess_search_results is not being called.

I'm trying to have the faceted_search module display its results through the same mechanism as the search module but it is strange that I cannot use the search module's theme functions.

Comments

jax’s picture

When I removed the search-results.tpl.php file from the theme directory it started working. This is strange behaviour since it does calls the preprocess function for the search-result.tpl.php file that is still in the theme directory. *boggle*

szy’s picture

So, finally - how have you themed seperate search result?

Assuming you are talking about faceted search?

Szy.

jax’s picture

Well, I created a separate module that themes it completely by itself:

/**
 * Implementation of hook_faceted_search_ui_style_info().
 */
function hfdb_faceted_search_ui_style_info() {
  return array(
    'custom hfdb' => new hfdb_custom_style,
  );
}

This module provides its own templates so that I can do whatever I want.

miki_nl’s picture

The presence of search-results.tpl.php and "existence" of template_preprocess_search_results(&$variables) in search.pages.inc is somehow corelated. If search-results.tpl.php is present on the theme directory, then function_exists('template_preprocess_search_results') indicates that this function does not exist. If I remove search-results.tpl.php (and clear cache) then the function template_preprocess_search_results suddenly exists.

syndicateStorm’s picture

Thanks for all the groundwork. Between this and http://drupal.org/node/343635 I was able to fix my problem quickly by following your lead.

I also copied template_preprocess_search_results from search.pages.inc and pasted it into my template.php file. This seamed to clear up the search-results.tpl.php not working properly. For reference here's what I put in my template file:

<?php
function mysite_preprocess_search_results(&$variables) {
  $variables['search_results'] = '';
  foreach ($variables['results'] as $result) {
    $variables['search_results'] .= theme('search_result', $result, $variables['type']);
  }
  $variables['pager'] = theme('pager', NULL, 10, 0);
  // Provide alternate search results template.
  $variables['template_files'][] = 'search-results-'. $variables['type'];
}
?>
2pha’s picture

Wow, I have this problem too. crazy