2.3 KiB
layout, title, nav
| layout | title | nav | ||
|---|---|---|---|---|
| default | search |
|
search
The search object has the following attributes:
{% anchor_link "search.performed", "search-performed" %}
Returns true if an HTML form with the attribute action="/search" was submitted successfully. This allows you to show content based on whether a search was performed or not.
{% anchor_link "search.results", "search-results" %}
Returns an array of matching search result items. The items in the array can be a:
You can access the attributes of the above three objects through search.results.
{{ item.title | link_to: item.url }}
{% if item.featured_image %} {% endif %} {{ item.content | strip_html | truncatewords: 40 | highlight: search.terms }} {% endfor %} {% endraw %}{% endhighlight %}{% anchor_link "search.results_count", "search-results_count" %}
Returns the number of results found.
{% anchor_link "search.terms", "search-terms" %}
Returns the string that was entered in the search input box. Use the highlight filter to apply a different style to any instances in the search results that match up with search.terms.
Input
{% highlight html %}{% raw %} {{ item.content | highlight: search.terms }} {% endraw %}{% endhighlight %}Output