Created
November 6, 2019 11:45
-
-
Save meredevelopment/67bb05d848b887a4e7a0816ba2d23a25 to your computer and use it in GitHub Desktop.
Using the t() function in Craft 3 CMS to show "# result" or "# results" based on count. Plurals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set searchQuery = craft.app.request.getParam('q') %} | |
{% set entries = craft.entries() | |
.search(searchQuery) | |
.orderBy('score') | |
.all() %} | |
{% if entries|length %} | |
<p> | |
{{ '{resCount,plural, | |
one{# result} | |
other{# results} | |
} ' | t ({resCount: entries|length }) }} | |
</p> | |
<ul> | |
{% for entry in entries %} | |
<li> | |
<a href="{{ entry.url }}">{{ entry.title }}</a> | |
{# etc etc etc #} | |
</li> | |
{% endfor %} | |
</ul> | |
{% else %} | |
<p>Your search for “{{ searchQuery }}” didn’t return any results.</p> | |
{% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment