4

Is it possible to change the output created with the Search module? I want to show custom fields, and I want to hide the description, user and date...

1
  • +1 Good question, what I need to do too, I've provided some comments as to the accepted answer as to the detail that worked for me. Jan 8, 2015 at 10:24

1 Answer 1

7

You have two options:

  1. You can use Display Suite module. A sub-module Display Suite Search allows you to change the way nodes are displayed for search results.

  2. You can use template_preprocess_search_result() together with a copy of modules/search/search-result.tpl.php in your theme. Read thoroughly the comments in the search-result.tpl.php as they will help you understand what is going on and what is available to you.
    You can define variables this way: $variables['your_value'] = $variables['result']['node']->field_sample[LANGUAGE_NONE][0]['value']; and use it in the .tpl file like this: print $your_value;.

6
  • Thanks for this straightforward answer! I'll take a look at this right away! Oct 19, 2012 at 15:19
  • I have all fields available in template_preprocess_search_result(), how do I use them in the .tpl file? Make a global variable? It's working that way, but is that the good way to do things like this? Oct 19, 2012 at 15:57
  • I updated my answer. Oct 19, 2012 at 16:30
  • Thanks mate, I loved Drupal before, and I'm loving it more and more, and a bit of the honour goes to you ;) Oct 20, 2012 at 8:23
  • You are welcome. Glad I helped. Oct 22, 2012 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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