# Pico-Search A plugin for the flat file CMS [Pico](https://github.com/picocms/Pico). Allows you to create a very basic search form that searches through titles and content of your pages. The search results page can filter the `pages` array to only contain pages matching the search terms. You can optionally scope the search to only get results from within a certain folder. For example, on the page `yoursite.com/blog/search/foobar`, the filtered array will only contain results from pages in the `blog` folder. ## Breaking changes as of January 2020 If you were using an earlier version of the plugin, the current version will not work as before. Previously the `pages` array was directly modified to filter and sort search results. This approach was not compatible with other Pico plugins and themes which depend on the `pages` array to contain all pages. Instead, this plugin now makes a Twig filter called `apply_search` available, which can be used in your templates to filter the `pages` array on demand: `{% set search_results = pages|apply_search %}`. This also makes it possible to combine with other plugins that behave similarly: `{% set results = pages|apply_search|paginate %}` ## Installation - **Copy the file `40-PicoSearch.php` to the `plugins` sub-folder of your Pico installation directory.** - **Add a file named `search.md` to your content root or the sub-folder you want to make searchable.** This is your search results page. You can leave it empty of content, but set the `Template` meta tag to a template that displays the filtered pages. Your `search.md` might look like this: ``` /* Title: Search results Template: search */ ``` - **Add a template file with the name defined in `search.md`.** Your template file (`search.twig` in the above example) should contain something like the following section, which lists the pages matching the search: ```twig {% if search_terms %}
{{ page.description }}
{% endif %}No results found for {{ search_terms|e('html') }}.
{% endif %}