Skip to content

Instantly share code, notes, and snippets.

@ryanirelan
Created November 8, 2018 18:56
Show Gist options
  • Save ryanirelan/df47bbce06d97c7fc3d306290c4f46c7 to your computer and use it in GitHub Desktop.
Save ryanirelan/df47bbce06d97c7fc3d306290c4f46c7 to your computer and use it in GitHub Desktop.
{# Using the example code from the docs #}
{% set searchQuery = craft.app.request.getParam('q') %}
{% set entries = craft.entries()
.search(searchQuery)
.orderBy('score')
.all() %}
{# You can do something like this where you just output the Section name #}
{% for entry in entries %}
<h4>{{ entry.section }}</h4>
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}
{# If you want to check for a certain section, you can do: #}
{% for entry in entries %}
{% if entry.section.handle == 'blog' %}<span class="ico blog"></span>{% endif %}
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment