PHP code example of distantnative / search-for-kirby
1. Go to this page and download the library: Download distantnative/search-for-kirby library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
distantnative / search-for-kirby example snippets
'search' => [
'entries' => [
'pages' => 'site.find("projects").index',
'files' => false,
// users will remain the default
]
]
// Simply add the field
'title',
// Add the field, but run it through a field method first
'text' => 'kirbytext',
// Pass parameters to the field method
'text' => ['short', 50],
// Use a callback function
'text' => function ($model) {
return strip_tags($model->text()->kt());
}
// Turn string field value into number (e.g. for Algolia filters)
'myNumberField' => function ($model) {
return $model->myNumberField()->toFloat();
}
'myVirtualNumberField' => function ($model) {
return $model->myNumberField()->toInt() + 5;
}
'myDate' => function ($model) {
return $model->anyDateField()->toTimestamp();
}
'search' => [
'templates' => [
'pages' => function ($model) {
return $model->id() !== 'home' && $model->id() !== 'error';
},
'files' => null,
'users' => null
]
]
``
If the value is null or an empty array, all templates are allowed. If it is false, all templates are excluded. There are several other options: