In Drupal 8, I am using 'Search API' template file to display search results. My each page has more than 1000 words content. When I perform a search it display the results correctly, but I see the full content in search results.

I just want to display 20 to 30 characters just as it display with default Drupal 8 search.

Here is the Code of Search Results page template:

{{ form }}

{% if search_title %}
<div class="ps19cms-search-result-title">
  <h2>{{ search_title }}</h2>
{% endif %}

<div class="ps19cms-api-search-results">
{{ results }}


The content is printed with {{results}}. How Can I break it so that instead of printing full body summary text, it only prints 20-30 characters but only those which matches with the keyword.


  • In your search view, you should be able to use the Summary or Trimmed formatter and limit the number of characters there.
    – CG Monroe
    Jul 9, 2019 at 18:36
  • Or if you need to do this in the twig template for some reason, see this answer: drupal.stackexchange.com/a/200318/78610
    – CG Monroe
    Jul 9, 2019 at 18:42
  • I have checked the above post, but if I apply slice function on text, then it will just show the characters of 1st result and hide the remaining results.
    – Eshban
    Jul 10, 2019 at 11:03
  • From indexer settings, I have select "Search results highlighting input" and it works fine. The only problem is that: It cannot highlight the text and do not show searched part of text in excerpts. It only shows first 30 characters. Any solution?
    – Eshban
    Jul 10, 2019 at 12:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.