Answers.Body: <p>Looking at the Happy Lager demo site there's a Short Description field, which functions as an excerpt for indexes and search results. I imagine P&amp;T use something similar for the Craft docs.</p>
  
  <p>You could also force your results onto one line and trim it with css, which is how P&amp;T do it on the Craft docs search results page:</p>
  
  <pre><code>li { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-20T11:56:39.057Z
Answers.LastActivityDate: 2015-08-20T11:56:39.057Z
Answers.UserDisplayName: Paul Grant
Answers.Body: <p>Have a look at the <a href="http://twig.sensiolabs.org/doc/filters/slice.html" rel="nofollow noreferrer"><code>slice</code></a> filter. To return 140 characters max. you would do something like this:</p>
  
  <pre><code>{% if entry.body %}
      {{ entry.body|slice(0, 140) }}
  {% endif %}
  </code></pre>
  
  <p>See <a href="https://craftcms.stackexchange.com/q/4361/125">this other question</a> on a similar topic if you want to apply this on a rich text field. Because this solution only works with plain text.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-19T15:58:31.630Z
Answers.Text: This thew an exception for me. `Calling unknown method: craft\elements\Entry::body()` I am using craft 3
Answers.UserDisplayName: Radmation
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-09-19T16:05:30.403Z
Answers.Text: Is that your field handle, `body`?
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-18T22:07:22.960Z
Answers.LastActivityDate: 2014-11-18T22:16:02.637Z
Answers.LastEditDate: 2017-04-13T12:51:00.303Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I use <a href="https://github.com/rkingon/Craft-Plugin--Trimmer" rel="nofollow">Trimmer</a> for this, it's pretty much the only plugin I use these days.</p>
  
  <p>I don't know for sure, but I suspect P&amp;T may use an 'excerpt' field to store a short sentence for use on the search results page, rather than cropping from longer copy.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-19T09:25:19.217Z
Answers.Text: Do I understand it right and this does remove all HTML tags? Again a deal breaker for rich text fields but otherwise a great little plugin. I especially like the option to trim before full words only.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-19T09:33:48.463Z
Answers.Text: Yes, it does strip HTML. There was a plugin for EE that would allow HTML and close any tags left open after trimming, I must try and find it to see if it can be/has been ported.
Answers.UserDisplayName: Steve Abraham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-13T18:19:30.017Z
Answers.Text: I added pull request for option to keep html tags [github](https://github.com/rkingon/Craft-Plugin--Trimmer/pull/7)
Answers.UserDisplayName: Vadim Goncharov
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-11-19T09:19:30.850Z
Answers.LastActivityDate: 2014-11-19T09:19:30.850Z
Answers.UserDisplayName: Steve Abraham
Body: <p>If I enter a query into the search bar I would like to see an excerpt (let's say 140 characters) of each entry that is related to the query. </p>
  
  <p>Here is what I use on the search result page to display the results.</p>
  
  <pre><code>{% set query = craft.request.getParam('q') %}
  {% set entries = craft.entries.search(query).order('score') %}
  
  {% if entries|length %}
  &lt;p&gt;{{ entries|length }} results:&lt;/p&gt;
  
  &lt;ul&gt;
      {% for entry in entries %}
          &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  {% else %}
  &lt;p&gt;Your search for “{{ query }}” didn’t return any results.&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>How do I add entry excerpts like: <a href="https://craftcms.com/search?q=entry" rel="nofollow noreferrer">https://craftcms.com/search?q=entry</a></p>
  
Tags: <entries><search>
Title: Get excerpt of entry from search query
ThreadText: # Get excerpt of entry from search query
  
  (Asked by: username_0 on 2014-11-18)
  
  If I enter a query into the search bar I would like to see an excerpt (let's say 140 characters) of each entry that is related to the query.
  
  Here is what I use on the search result page to display the results.
  
  ```
  {% set query = craft.request.getParam('q') %}
  {% set entries = craft.entries.search(query).order('score') %}
  
  {% if entries|length %}
  <p>{{ entries|length }} results:</p>
  
  <ul>
      {% for entry in entries %}
          <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
      {% endfor %}
  </ul>
  {% else %}
  <p>Your search for “{{ query }}” didn’t return any results.</p>
  {% endif %}
  
  ```
  
  How do I add entry excerpts like: <https://craftcms.com/search?q=entry>
  
  **Tags:** entries, search
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-08-20. Score: 3
  
  Looking at the Happy Lager demo site there's a Short Description field, which functions as an excerpt for indexes and search results. I imagine P&T use something similar for the Craft docs.
  
  You could also force your results onto one line and trim it with css, which is how P&T do it on the Craft docs search results page:
  
  ```
  li { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2014-11-18. Score: 3
  
  Have a look at the [`slice`](http://twig.sensiolabs.org/doc/filters/slice.html) filter. To return 140 characters max. you would do something like this:
  
  ```
  {% if entry.body %}
      {{ entry.body|slice(0, 140) }}
  {% endif %}
  
  ```
  
  See [this other question](https://craftcms.stackexchange.com/q/4361/125) on a similar topic if you want to apply this on a rich text field. Because this solution only works with plain text.
  
  > **Comments:**
  > **username_3**: This thew an exception for me. `Calling unknown method: craft\elements\Entry::body()` I am using craft 3  
  > **username_2**: Is that your field handle, `body`?  
  
  ---
  
  ### Answer by username_4 on 2014-11-19. Score: 2
  
  I use [Trimmer](https://github.com/rkingon/Craft-Plugin--Trimmer) for this, it's pretty much the only plugin I use these days.
  
  I don't know for sure, but I suspect P&T may use an 'excerpt' field to store a short sentence for use on the search results page, rather than cropping from longer copy.
  
  > **Comments:**
  > **username_2**: Do I understand it right and this does remove all HTML tags? Again a deal breaker for rich text fields but otherwise a great little plugin. I especially like the option to trim before full words only.  
  > **username_4**: Yes, it does strip HTML. There was a plugin for EE that would allow HTML and close any tags left open after trimming, I must try and find it to see if it can be/has been ported.  
  > **username_5**: I added pull request for option to keep html tags [github](https://github.com/rkingon/Craft-Plugin--Trimmer/pull/7)  
  
  ---
  
  