How do I group entries by section? I have search results:
{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
But I want to have
SECTION NAME entry 1 entry 4 entry 6
SECTION NAME entry 3 entry 12
etc.
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityYou can use the Twig group filter.
{% set entries = allowedSearchableEntries.search(query).order('score').limit(100) %}
{% set entriesBySection = entries|group('section') %}
{% for section, entriesInSection in entriesBySection %}
<h2>{{ section }}</h2>
<ul>
{% for entry in entriesInSection %}
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}
</ul>
{% endfor %}