search-result.html.twig

Same filename in this branch
  1. 9 core/profiles/demo_umami/themes/umami/templates/classy/content/search-result.html.twig
  2. 9 core/themes/olivero/templates/content/search-result.html.twig
  3. 9 core/themes/stable9/templates/content/search-result.html.twig
  4. 9 core/themes/seven/templates/classy/content/search-result.html.twig
  5. 9 core/themes/claro/templates/classy/content/search-result.html.twig
  6. 9 core/themes/bartik/templates/classy/content/search-result.html.twig
  7. 9 core/themes/stable/templates/content/search-result.html.twig
  8. 9 core/themes/starterkit_theme/templates/content/search-result.html.twig
  9. 9 core/modules/search/templates/search-result.html.twig
Same filename in other branches
  1. 8.9.x core/profiles/demo_umami/themes/umami/templates/classy/content/search-result.html.twig
  2. 8.9.x core/themes/seven/templates/classy/content/search-result.html.twig
  3. 8.9.x core/themes/claro/templates/classy/content/search-result.html.twig
  4. 8.9.x core/themes/bartik/templates/classy/content/search-result.html.twig
  5. 8.9.x core/themes/stable/templates/content/search-result.html.twig
  6. 8.9.x core/themes/classy/templates/content/search-result.html.twig
  7. 8.9.x core/modules/search/templates/search-result.html.twig
  8. 10 core/profiles/demo_umami/themes/umami/templates/classy/content/search-result.html.twig
  9. 10 core/themes/olivero/templates/content/search-result.html.twig
  10. 10 core/themes/stable9/templates/content/search-result.html.twig
  11. 10 core/themes/claro/templates/classy/content/search-result.html.twig
  12. 10 core/themes/starterkit_theme/templates/content/search-result.html.twig
  13. 10 core/modules/search/templates/search-result.html.twig
  14. 11.x core/profiles/demo_umami/themes/umami/templates/classy/content/search-result.html.twig
  15. 11.x core/themes/olivero/templates/content/search-result.html.twig
  16. 11.x core/themes/stable9/templates/content/search-result.html.twig
  17. 11.x core/themes/claro/templates/classy/content/search-result.html.twig
  18. 11.x core/themes/starterkit_theme/templates/content/search-result.html.twig
  19. 11.x core/modules/search/templates/search-result.html.twig

Theme override for displaying a single search result.

This template renders a single search result. The list of results is rendered using '#theme' => 'item_list', with suggestions of:

  • item_list__search_results__(plugin_id)
  • item_list__search_results

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.
  • plugin_id: The machine-readable name of the plugin being executed,such as "node_search" or "user_search".
  • title_prefix: Additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • title_suffix: Additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
  • info_split: Contains same data as info, but split into separate parts.
    • info_split.type: Node type (or item type string supplied by module).
    • 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).

@todo The info variable needs to be made drillable and each of these sub items should instead be within info and renamed info.foo, info.bar, etc.

Other variables:

  • title_attributes: HTML attributes for the title.
  • content_attributes: HTML attributes for the content.

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.


  {% if (info_split.comment) %}
    <span class="info-comment">
      {{ info_split.comment }}
    </span>
  {% endif %}

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


  <pre>
    {{ dump(info_split) }}
  </pre>

See also

template_preprocess_search_result()

2 theme calls to search-result.html.twig
SearchExtraTypeSearch::buildResults in core/modules/search/tests/modules/search_extra_type/src/Plugin/Search/SearchExtraTypeSearch.php
Executes the search and builds render arrays for the result items.
SearchPluginBase::buildResults in core/modules/search/src/Plugin/SearchPluginBase.php
Executes the search and builds render arrays for the result items.

File

core/themes/classy/templates/content/search-result.html.twig

View source
  1. {#
  2. /**
  3. * @file
  4. * Theme override for displaying a single search result.
  5. *
  6. * This template renders a single search result. The list of results is
  7. * rendered using '#theme' => 'item_list', with suggestions of:
  8. * - item_list__search_results__(plugin_id)
  9. * - item_list__search_results
  10. *
  11. * Available variables:
  12. * - url: URL of the result.
  13. * - title: Title of the result.
  14. * - snippet: A small preview of the result. Does not apply to user searches.
  15. * - info: String of all the meta information ready for print. Does not apply
  16. * to user searches.
  17. * - plugin_id: The machine-readable name of the plugin being executed,such
  18. * as "node_search" or "user_search".
  19. * - title_prefix: Additional output populated by modules, intended to be
  20. * displayed in front of the main title tag that appears in the template.
  21. * - title_suffix: Additional output populated by modules, intended to be
  22. * displayed after the main title tag that appears in the template.
  23. * - info_split: Contains same data as info, but split into separate parts.
  24. * - info_split.type: Node type (or item type string supplied by module).
  25. * - info_split.user: Author of the node linked to users profile. Depends
  26. * on permission.
  27. * - info_split.date: Last update of the node. Short formatted.
  28. * - info_split.comment: Number of comments output as "% comments", %
  29. * being the count. (Depends on comment.module).
  30. * @todo The info variable needs to be made drillable and each of these sub
  31. * items should instead be within info and renamed info.foo, info.bar, etc.
  32. *
  33. * Other variables:
  34. * - title_attributes: HTML attributes for the title.
  35. * - content_attributes: HTML attributes for the content.
  36. *
  37. * Since info_split is keyed, a direct print of the item is possible.
  38. * This array does not apply to user searches so it is recommended to check
  39. * for its existence before printing. The default keys of 'type', 'user' and
  40. * 'date' always exist for node searches. Modules may provide other data.
  41. * @code
  42. * {% if (info_split.comment) %}
  43. * <span class="info-comment">
  44. * {{ info_split.comment }}
  45. * </span>
  46. * {% endif %}
  47. * @endcode
  48. *
  49. * To check for all available data within info_split, use the code below.
  50. * @code
  51. * <pre>
  52. * {{ dump(info_split) }}
  53. * </pre>
  54. * @endcode
  55. *
  56. * @see template_preprocess_search_result()
  57. */
  58. #}
  59. {{ attach_library('classy/search-results') }}
  60. {{ title_prefix }}
  61. <h3{{ title_attributes.addClass('search-result__title') }}>
  62. <a href="{{ url }}">{{ title }}</a>
  63. </h3>
  64. {{ title_suffix }}
  65. <div class="search-result__snippet-info">
  66. {% if snippet %}
  67. <p{{ content_attributes.addClass('search-result__snippet') }}>{{ snippet }}</p>
  68. {% endif %}
  69. {% if info %}
  70. <p class="search-result__info">{{ info }}</p>
  71. {% endif %}
  72. </div>

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.