search-result.tpl.php

  1. 7.x drupal-7.x/modules/search/search-result.tpl.php
  2. 6.x drupal-6.x/modules/search/search-result.tpl.php

search-result.tpl.php Default theme implementation for displaying a single search result.

This template renders a single search result and is collected into search-results.tpl.php. This and the parent template are dependent to one another sharing the markup for definition lists.

Available variables:

  • $url: URL of the result.
  • $title: Title of the result.
  • $snippet: A small preview of the result. Does not apply to user searches.
  • $info: String of all the meta information ready for print. Does not apply to user searches.
  • $info_split: Contains same data as $info, split into a keyed array.
  • $type: The type of search, e.g., "node" or "user".

Default keys within $info_split:

  • $info_split['type']: Node type.
  • $info_split['user']: Author of the node linked to users profile. Depends on permission.
  • $info_split['date']: Last update of the node. Short formatted.
  • $info_split['comment']: Number of comments output as "% comments", % being the count. Depends on comment.module.
  • $info_split['upload']: Number of attachments output as "% attachments", % being the count. Depends on upload.module.

Since $info_split is keyed, a direct print of the item is possible. This array does not apply to user searches so it is recommended to check for their existance before printing. The default keys of 'type', 'user' and 'date' always exist for node searches. Modules may provide other data.

<?php if (isset($info_split['comment'])) : ?> <span class="info-comment"> <?php print $info_split['comment']; ?> </span> <?php endif; ?>

To check for all available data within $info_split, use the code below.

<?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>

See also

template_preprocess_search_result()

2 theme calls to search-result.tpl.php
hook_search_page in documentation-6.x/developer/hooks/core.php
Override the rendering of search results.
template_preprocess_search_results in drupal-6.x/modules/search/search.pages.inc
Process variables for search-results.tpl.php.

File

drupal-6.x/modules/search/search-result.tpl.php
View source
  1. <?php
  2. /**
  3. * @file search-result.tpl.php
  4. * Default theme implementation for displaying a single search result.
  5. *
  6. * This template renders a single search result and is collected into
  7. * search-results.tpl.php. This and the parent template are
  8. * dependent to one another sharing the markup for definition lists.
  9. *
  10. * Available variables:
  11. * - $url: URL of the result.
  12. * - $title: Title of the result.
  13. * - $snippet: A small preview of the result. Does not apply to user searches.
  14. * - $info: String of all the meta information ready for print. Does not apply
  15. * to user searches.
  16. * - $info_split: Contains same data as $info, split into a keyed array.
  17. * - $type: The type of search, e.g., "node" or "user".
  18. *
  19. * Default keys within $info_split:
  20. * - $info_split['type']: Node type.
  21. * - $info_split['user']: Author of the node linked to users profile. Depends
  22. * on permission.
  23. * - $info_split['date']: Last update of the node. Short formatted.
  24. * - $info_split['comment']: Number of comments output as "% comments", %
  25. * being the count. Depends on comment.module.
  26. * - $info_split['upload']: Number of attachments output as "% attachments", %
  27. * being the count. Depends on upload.module.
  28. *
  29. * Since $info_split is keyed, a direct print of the item is possible.
  30. * This array does not apply to user searches so it is recommended to check
  31. * for their existance before printing. The default keys of 'type', 'user' and
  32. * 'date' always exist for node searches. Modules may provide other data.
  33. *
  34. * <?php if (isset($info_split['comment'])) : ?>
  35. * <span class="info-comment">
  36. * <?php print $info_split['comment']; ?>
  37. * </span>
  38. * <?php endif; ?>
  39. *
  40. * To check for all available data within $info_split, use the code below.
  41. *
  42. * <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
  43. *
  44. * @see template_preprocess_search_result()
  45. */
  46. ?>
  47. <dt class="title">
  48. <a href="<?php print $url; ?>"><?php print $title; ?></a>
  49. </dt>
  50. <dd>
  51. <?php if ($snippet) : ?>
  52. <p class="search-snippet"><?php print $snippet; ?></p>
  53. <?php endif; ?>
  54. <?php if ($info) : ?>
  55. <p class="search-info"><?php print $info; ?></p>
  56. <?php endif; ?>
  57. </dd>