search-result.tpl.php

  1. 7.x drupal/modules/search/search-result.tpl.php
  2. 6.x drupal/modules/search/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.
  • $module: The machine-readable name of the module (tab) being searched, such as "node" or "user".
  • $title_prefix (array): An array containing additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • $title_suffix (array): An array containing additional output populated by modules, intended to be displayed after the main title tag that appears in the template.

Default keys within $info_split:

  • $info_split['module']: The module that implemented the search query.
  • $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.

Other variables:

  • $classes_array: Array of HTML class attribute values. It is flattened into a string within the variable $classes.
  • $title_attributes_array: Array of HTML attributes for the title. It is flattened into a string within the variable $title_attributes.
  • $content_attributes_array: Array of HTML attributes for the content. It is flattened into a string within the variable $content_attributes.

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 its existence before printing. The default keys of 'type', 'user' and 'date' always exist for node searches. Modules may provide other data.

<?php
  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
  php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
?>

See also

template_preprocess()

template_preprocess_search_result()

template_process()

1 theme call to search-result.tpl.php
template_preprocess_search_results in drupal/modules/search/search.pages.inc
Process variables for search-results.tpl.php.
10 string references to the theme hook from search-result.tpl.php

Note: this list is generated by looking for the string for this theme hook, so it may include some references that are not actually using this theme hook.

comment_node_view in drupal/modules/comment/comment.module
Implements hook_node_view().
hook_entity_info in drupal/modules/system/system.api.php
Inform the base system and the Field API about one or more entity types.
hook_search_execute in drupal/modules/search/search.api.php
Execute a search for a set of key words.
hook_search_page in drupal/modules/search/search.api.php
Override the rendering of search results.
node_entity_info in drupal/modules/node/node.module
Implements hook_entity_info().

... See full list

File

drupal/modules/search/search-result.tpl.php
View source
  1. <?php
  2. /**
  3. * @file
  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. * - $module: The machine-readable name of the module (tab) being searched, such
  18. * as "node" or "user".
  19. * - $title_prefix (array): An array containing additional output populated by
  20. * modules, intended to be displayed in front of the main title tag that
  21. * appears in the template.
  22. * - $title_suffix (array): An array containing additional output populated by
  23. * modules, intended to be displayed after the main title tag that appears in
  24. * the template.
  25. *
  26. * Default keys within $info_split:
  27. * - $info_split['module']: The module that implemented the search query.
  28. * - $info_split['user']: Author of the node linked to users profile. Depends
  29. * on permission.
  30. * - $info_split['date']: Last update of the node. Short formatted.
  31. * - $info_split['comment']: Number of comments output as "% comments", %
  32. * being the count. Depends on comment.module.
  33. *
  34. * Other variables:
  35. * - $classes_array: Array of HTML class attribute values. It is flattened
  36. * into a string within the variable $classes.
  37. * - $title_attributes_array: Array of HTML attributes for the title. It is
  38. * flattened into a string within the variable $title_attributes.
  39. * - $content_attributes_array: Array of HTML attributes for the content. It is
  40. * flattened into a string within the variable $content_attributes.
  41. *
  42. * Since $info_split is keyed, a direct print of the item is possible.
  43. * This array does not apply to user searches so it is recommended to check
  44. * for its existence before printing. The default keys of 'type', 'user' and
  45. * 'date' always exist for node searches. Modules may provide other data.
  46. * @code
  47. * <?php if (isset($info_split['comment'])): ?>
  48. * <span class="info-comment">
  49. * <?php print $info_split['comment']; ?>
  50. * </span>
  51. * <?php endif; ?>
  52. * @endcode
  53. *
  54. * To check for all available data within $info_split, use the code below.
  55. * @code
  56. * <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
  57. * @endcode
  58. *
  59. * @see template_preprocess()
  60. * @see template_preprocess_search_result()
  61. * @see template_process()
  62. *
  63. * @ingroup themeable
  64. */
  65. ?>
  66. <li class="<?php print $classes; ?>"<?php print $attributes; ?>>
  67. <?php print render($title_prefix); ?>
  68. <h3 class="title"<?php print $title_attributes; ?>>
  69. <a href="<?php print $url; ?>"><?php print $title; ?></a>
  70. </h3>
  71. <?php print render($title_suffix); ?>
  72. <div class="search-snippet-info">
  73. <?php if ($snippet): ?>
  74. <p class="search-snippet"<?php print $content_attributes; ?>><?php print $snippet; ?></p>
  75. <?php endif; ?>
  76. <?php if ($info): ?>
  77. <p class="search-info"><?php print $info; ?></p>
  78. <?php endif; ?>
  79. </div>
  80. </li>

Related topics