3

I am seeing 2 functions like template_preprocess_search_result() and template_preprocess_search_results() in Drupal 7. I just got confused on which function I should use when modifying my search results.

Can anyone tell me what the basic difference between these 2 functions is?

10

template_preprocess_search_result is to process variables for search-result.tpl.php which will render output for each of the search result independently.

template_preprocess_search_results is to process variables for search-results.tpl.php which will render output after each of the search result is already rendered through search-result.tpl.php

For example, if there are 4 search results. for each of the results search-result.tpl.php will be used. and at the end search-results.tpl.php will be used. Ending up using search-result.tpl.php for 4 times for each of the results and search-results.tpl.php only once at the end.

Hope that is clear.

2

It depends what you want to change.

The one could be used for changing the markup for the actual result, for example headline + trimmed description, while the other is for all the results for example list, table or divs.

So you might need to use one or both, or maybe just use template files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.