Reference

Guide

Search

Add your own search engine

If you are not happy with our built-in search for collections, you can create your own.

/site/plugins/my-search/index.php
Kirby::plugin('my/search', [
   'components' => [
      'search' => function (Kirby $kirby, Collection $collection, string $query = null, $params = []) {

            // only search in the field named keywords
            $result = $collection->filterBy('keywords', '*=', $query);

            return $result;
        }
  ]
]);

Parameters

Name Type Default Description
$kirby Kirby\Cms\App

Kirby instance

$collection Kirby\Cms\Collection

Collection of searchable models

$query string null
$params mixed [ ]

Return type

Kirby\Cms\Collection|bool

Source code

kirby/config/components.php#L150