search-result.html.twig in Drupal 10
Same filename in this branch
- 10 core/modules/search/templates/search-result.html.twig
- 10 core/themes/starterkit_theme/templates/content/search-result.html.twig
- 10 core/themes/classy/templates/content/search-result.html.twig
- 10 core/themes/olivero/templates/content/search-result.html.twig
- 10 core/themes/stable9/templates/content/search-result.html.twig
- 10 core/themes/stable/templates/content/search-result.html.twig
- 10 core/themes/claro/templates/classy/content/search-result.html.twig
- 10 core/themes/seven/templates/classy/content/search-result.html.twig
- 10 core/themes/bartik/templates/classy/content/search-result.html.twig
- 10 core/profiles/demo_umami/themes/umami/templates/classy/content/search-result.html.twig
Same filename and directory in other branches
Default theme implementation 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
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/modules/search/templates/search-result.html.twigView source
- {#
- /**
- * @file
- * Default theme implementation 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.
- * @code
- * {% if (info_split.comment) %}
- * <span class="info-comment">
- * {{ info_split.comment }}
- * </span>
- * {% endif %}
- * @endcode
- *
- * To check for all available data within info_split, use the code below.
- * @code
- * <pre>
- * {{ dump(info_split) }}
- * </pre>
- * @endcode
- *
- * @see template_preprocess_search_result()
- *
- * @ingroup themeable
- */
- #}
- {{ title_prefix }}
- <h3{{ title_attributes }}>
- <a href="{{ url }}">{{ title }}</a>
- </h3>
- {{ title_suffix }}
- {% if snippet %}
- <p{{ content_attributes }}>{{ snippet }}</p>
- {% endif %}
- {% if info %}
- <p>{{ info }}</p>
- {% endif %}