Hello !
I’m building a simple subpage filtering menu with tags, and I was wondering if there was an easy way to “Toggle” the filtering. For example: on the first click the tag is active, and if you select It again the filtering is gone and all the subpages are displayed.
Here is my tag snippet
<?php foreach($topics as $topic): ?>
<a class="tag" href="<?= url($page->url(), ['params' => ['topic' => urlencode($topic)]]) ?>" ><?= html($topic) ?><span class="em-space"></span></a>
<?php endforeach ?>
And the Controller
<?php
return function ($kirby, $pages, $page) {
$projets = $page->children()->filterBy('template', 'projet');
$topics = $projets->pluck('topics', ',', true);
if($topic = urldecode(param('topic'))) {
$projets = $projets->filterBy('topics', $topic, ',');
}
return compact('topics', 'topic', 'projets');
};
Thank you !