<p>There is no way at present to delegate a field as the search excerpt field in Craft, so it needs to be handled by the search results template. It is possible to use conditionals but this can bloat the template, especially when there are multiple sections and each section outputs different fields in different ways, so I prefer to create dedicated search excerpt templates and include them in the search results template as follows:</p>

<pre><code>{% include ['_search-excerpts/' ~ entry.section.handle, '_search-excerpts/default'] %}
</code></pre>

<p>The above code will render the section's dedicated search excerpt template if it exists in a folder called <em>_search-excerpts</em>, otherwise it will render the default search excerpt template which can contain for example:</p>

<pre><code>&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
</code></pre>

<p>The resulting folder structure would then look like this:</p>

<pre><code>_search-excerpts/default.html
_search-excerpts/sectionA.html
_search-excerpts/sectionB.html
_search-excerpts/sectionC.html
</code></pre>

CC BY-SA 3.0
2014-06-13T09:36:18.987Z
2014-06-26T17:50:01.450Z
2014-06-26T17:50:01.450Z
Ben Croker
<p>This can be accomplished using a conditional:</p>

<pre><code>{% if entry.section == 'sectionA' %}
    {{ entry.sectionAField }}
{% elseif entry.section == 'sectionB' %}
    {{ entry.sectionBField }}
{% endif %}
</code></pre>

<p>or a switch statement:</p>

<pre><code>{% switch entry.section %}
    {% case "sectionA" %}
       {{ entry.sectionAField }}
    {% case "sectionB" %}
       {{ entry.sectionBField }}
{% endswitch %}
</code></pre>

CC BY-SA 3.0
2014-06-13T22:59:08.110Z
Worth noting that one of the big advantages of being able to share field across sections is that a lot of the time the excerpt field will be the same so no need for the if's but when it's not you got the right idea
Keith Mancuso
CC BY-SA 3.0
2014-06-12T17:02:14.123Z
2014-07-17T22:11:25.503Z
2014-07-17T22:11:25.503Z
Anna_MediaGirl
<p>How do I create search result page "excerpts" when there are multiple sections/fields that need to be represented?</p>

<search>
How can I display search "excerpts" from multiple sections?
# How can I display search "excerpts" from multiple sections?

(Asked by: username_0 on 2014-06-12)

How do I create search result page "excerpts" when there are multiple sections/fields that need to be represented?

**Tags:** search

---

## 2 answers

### Answer by username_0 on 2014-06-12. Score: 9 | Accepted answer

This can be accomplished using a conditional:
{% if entry.section == 'sectionA' %}
    {{ entry.sectionAField }}
{% elseif entry.section == 'sectionB' %}
    {{ entry.sectionBField }}
{% endif %}

or a switch statement:
{% switch entry.section %}
    {% case "sectionA" %}
       {{ entry.sectionAField }}
    {% case "sectionB" %}
       {{ entry.sectionBField }}
{% endswitch %}

> **Comments:**
> **username_2**: Worth noting that one of the big advantages of being able to share field across sections is that a lot of the time the excerpt field will be the same so no need for the if's but when it's not you got the right idea  

---

### Answer by username_1 on 2014-06-13. Score: 11

There is no way at present to delegate a field as the search excerpt field in Craft, so it needs to be handled by the search results template. It is possible to use conditionals but this can bloat the template, especially when there are multiple sections and each section outputs different fields in different ways, so I prefer to create dedicated search excerpt templates and include them in the search results template as follows:
{% include ['_search-excerpts/' ~ entry.section.handle, '_search-excerpts/default'] %}

The above code will render the section's dedicated search excerpt template if it exists in a folder called _search-excerpts, otherwise it will render the default search excerpt template which can contain for example:
{{ entry.title }}

The resulting folder structure would then look like this:
_search-excerpts/default.html
_search-excerpts/sectionA.html
_search-excerpts/sectionB.html
_search-excerpts/sectionC.html


---

