Hi
I would like to uncheck tag when one of these is active. For example, on ..../tag:IN%2BSITU/date:current
, when date
tag is clicked again, the url would be : .../tag:IN%2BSITU
only, in order to uncheck date.
My controller :
<?php
return function ($site, $kirby, $pages, $page) {
$query = get('q');
$results = $site->search($query, 'title|text|title_notice|domain|description');
$articlesexpo = $site->find('expositions')->children()->listed()->sortBy('datedebut', 'desc');
if($tagexpo = urldecode(param('tag'))) {
$articlesexpo = $articlesexpo->filterBy('tags', $tagexpo, ',');
}
if($datetag = urldecode(param('date'))) {
$articlesexpo = $articlesexpo->filter(function($item) use($datetag) {
if ($datetag === 'future') {
return $item->datedebut()->toDate() > time();
}
if ($datetag === 'passe') {
return $item->datefin()->toDate() < time();
}
if ($datetag === 'current') {
return $item->datedebut()->toDate() <= time() && $item->datefin()->toDate() >= time();
}
return $item->datedebut()->toDate('Y') === $datetag;
});
}
$tagsexpo = $articlesexpo->pluck('tags', ',', true);
$collator = new Collator('fr_FR');
$collator->sort($tagsexpo);
$articlesexpo = $articlesexpo->paginate(5);
$paginationexpo = $articlesexpo->pagination();
return [
'articlesexpo' => $articlesexpo,
'tagsexpo' => $tagsexpo,
'tagexpo' => $tagexpo,
'paginationexpo' => $paginationexpo,
'datetag' => $datetag,
'query' => $query,
'results' => $results,
];
};
my template :
<ul>
<li>
<a class="<?= param('date') == 'future' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'future']) ]) ?>"><?= t('avenir') ?></a>
</li>
<li>
<a class="<?= param('date') == 'current' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'current']) ]) ?>"><?= t('encours') ?></a>
</li>
<li>
<a class="<?= param('date') == 'passe' ? 'active' : '' ?>" href="<?= url($page->url(), ['params' => array_merge(params(),['date' => 'passe']) ]) ?>"><?= t('passe') ?></a>
</li>
<?php foreach($tagsexpo as $tag): ?>
<li>
<a <?php e($tag === urldecode(param('tag')), 'class="active"', '') ?> href="<?= url($page->url(), ['params' => array_merge(params(),['tag' => urlencode($tag)]) ]) ?>">
<?= html($tag) ?>
</a>
</li>
<?php endforeach ?>
</ul>