Mona
January 17, 2023, 3:53pm
1
Hi, is it possible to display in a template, tags as checkboxes, with multiple choice options? Like in this example: Projects - Wanzenried & Partner
I can manage it with 1 tag with filterby but not with multiple tags selection.
Thank you very much for your help.
Best
Could you please post the code you tried, both form part with the checkboxes and the filter logic in your controller/template?
Mona
January 18, 2023, 9:07am
3
Right now, I have this option who manage one tag at the time:
I would like to do the same thing with “checkboxes” and multiple selection possible, also with projects that have multiple tags. Is it possible with this method “Filterby”?
Filter:
<?php
$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$projects = $unfiltered
->when($filterBy, function($filterBy) {
return $this->filterBy('tags', ' ', $filterBy);
});
$filters = $unfiltered->pluck('tags', ' ', true);
?>
Menu:
Items:
<?php foreach ($projects as $project): ?>
<div class="cell large-4">
<div class="<?= $project->tags() ?>">
<a href="<?= $project->url() ?>">
<h3><?= $project->title() ?></h3>
</a>
</div>
</div>
<?php endforeach ?>
Mona
January 18, 2023, 9:09am
4
Ouh sorry the code went weird
<?php
$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$projects = $unfiltered
->when($filterBy, function($filterBy) {
return $this->filterBy('tags', ' ', $filterBy);
});
$filters = $unfiltered->pluck('tags', ' ', true);
?>
<ul>
<li><a href="<?= $page->url() ?>">Alle</a><span></span></li>
<?php foreach ($filters as $filter): ?>
<li>
<a href="<?= $page->url() ?>?filter=<?= $filter ?>"><?= $filter ?>
</a><span></span></li>
<?php endforeach ?>
</ul>
<?php foreach ($projects as $project): ?>
<div class="cell large-4">
<div class="<?= $project->tags() ?>">
<a href="<?= $project->url() ?>">
<h3><?= $project->title() ?></h3>
</a>
</div>
</div>
<?php endforeach ?>
texnixe
January 18, 2023, 11:39am
5
The first step would be to convert your list of links to checkboxes, because multiple tags cannot be selected via links.
The second step is then to change the filter by using
The result don’t have to match all tags (or)
return $this->filterBy('tags', 'in', $filterBy);
The result should match all selected tags (and)
return $this->filter(fn($item) => sort($item->tags()->split()) === sort($filterBy));