1. Go to this page and download the library: Download hksagentur/kirby-facets 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/ */
hksagentur / kirby-facets example snippets
use Hks\Facets\Http\Filter;
use Hks\Facets\Http\Filters;
$filters = Filters::for($page->children()->listed())
->add(Filter::in('season'));
$concerts = $filters->apply();
Filter::in('season'); // reads ?season=..., filters the season attribute
Filter::in(name: 'spielzeit', attribute: 'season'); // reads ?spielzeit=..., filters the season attribute
Filter::in('season')->from('spielzeit');
// ->attribute() still returns 'season'; only ->name() becomes 'spielzeit'
use Hks\Facets\Form\Facet;
use Hks\Facets\Form\Facets;
$facets = new Facets([
Facet::checkboxes('season', 'Season', fn () => Seasons::options()),
Facet::date('date', 'Date'),
Facet::toggle('musiktheater', 'Musiktheater'),
]);
echo $facets;
foreach ($facets as $facet):
foreach ($facet->options() as $option):
Facet::radio('season', 'Season', fn () => $kirby->collection('seasons')->toFacetOptions());
Facet::radio('category', 'Category', fn () => $categories->toFacetOptions(label: 'name')); // Structure: no title(), has 'id'/'name'
Facet::radio('house_type', 'House type', fn () => $page->houseTypes()->toFacetOptions(icon: 'icon')); // reads the page's own `icon` field
public function __invoke(Collection $collection): Collection
{
return $this->isEmpty() ? $collection : $this->apply($collection);
}
namespace App\Filters;
use Hks\Facets\Http\Filter\Attribute;
use Kirby\Cms\Collection;
class GreaterThan extends Attribute
{
public function apply(Collection $collection): Collection
{
return $collection->filterBy($this->attribute(), '>', $this->value());
}
}