match anything after http://artoteca.dev/catalogo with a regex
return new url structure
it should change based on the site language, so technique should actually be something else for both the default language (italian) and the alternative language (german). This part is still missing below.
It still is not wokring (no url redirect and the filter does not return any result), but at least it was useful to understand the logic behind routing.
Thank you again for your help, still no luck on my side.
I suspected there was a problem in using the same $artworks variable multiple times in the controller, but I tried to make a new one only for the router and instead of showing no result, it displayed all results.
Below my full controller:
<?php
return function($site, $pages, $page, $args) {
//++ artworks
$artworks = $page->children('template', 'artworks')->children()->visible();
//++ technique
$techniques = $artworks->pluck('technique', ',', true);
asort($techniques);
if(!empty(param('technique'))) {
$artworks = $artworks->filter(function($result) use($techniques) {
// split tags and convert to lowercase
$techniques = array_map('str::slug', $result->technique()->split(','));
// return the page if the filter is in the array
if(in_array(str::slug(param('technique')), $techniques)) return true;
});
}
$p_technique = kirby()->request()->params()->technique();
//++ route: filter artworks by tag
if(isset($args['technique'])) {
$artworks = $artworks->filterBy('technique', $args['technique'], ',');
}
//++ author
$authors = $page->children()->findBy('intendedTemplate', 'authors')->children()->visible();
$p_author = kirby()->request()->params()->author();
// search
// + + + +
// return all children if nothing is selected
$query = get('q');
if($query) {
$artworks = $artworks->search($query, 'title|text');
}
$artworks = $artworks->paginate(20);
$pagination = $artworks->pagination();
// return
// + + + +
return compact ('artworks', 'techniques', 'p_technique', 'authors', 'p_author', 'query', 'pagination');
};