Hey,
I created a filterable portfolio.
The categories are created in the site.yml
site.yml
immobilien_kategorien:
label: Immobilien-Kategorien
type: structure
fields:
kategorie:
label: Kategorie
type: text
kategorie_slug:
label: Titelform
type: slug
sync: kategorie
The filter function and menu looks like this:
template.php
<?php
$filterBy = get('filter');
$unfiltered = $page->children()->listed();
$immobilien = $unfiltered
->when($filterBy, function($filterBy) {
return $this->filterBy('kat_immo', $filterBy);
});
$filters = $unfiltered->pluck('kat_immo', ',', true);
?>
...
<nav>
<a class="button" href="<?= $page->url() ?>">Alle Immobilien</a>
<?php foreach ($filters as $filter): ?>
<a class="button" href="<?= $page->url()?>?filter=<?= $filter ?>"><?= $filter ?></a>
<?php endforeach ?>
</nav>
The url for “Häuser” is
…?filter=hauser → but it should be …?filter=haeuser
The menu label is “hauser” → but it should be “Häuser”.
In my config.php i add 'slugs' => 'de',
Where is the mistake?
Thank you
texnixe
September 7, 2022, 5:33pm
2
Works for me. Could you post your complete config.php?
Not sure which values your are plucking here…
config.php
<?php
return [
'debug' => true,
'panel' => [
'css' => 'assets/css/custom-panel.css'
],
'slugs' => 'de',
];
Oh dear I forgot to show the template.yml
fields:
kat_immo:
label: Kategorie
type: select
options: query
query:
fetch: site.immobilien_kategorien.toStructure
text: "{{ structureItem.kategorie }}"
value: "{{ structureItem.kategorie_slug }}"
Here I choose a category that is defined in the structure field (site.yml).
texnixe
September 8, 2022, 11:17am
4
To get the category name as defined in the category structure field, you would have to fetch the kategorie
that corresponds to the slug from this structure field, because you only have the slug in your kat_immo
field.
Your config looks fine. What’s your Kirby version?
I don’t know where and how i have to fetch the kategorie
in the template.php.
I tried different ways that I found here in the forum but nothing worked.
texnixe
September 12, 2022, 11:18am
7
Check out this example, it’s basically the same problem: Display query text and value - #6 by texnixe
Thanks for the example. I’ve tried something around without success.
But I’m one step further. After I saved the data set again, the urls are now at least correct.
So the url is ...?filter=haeuser
how it should be!
But the filterlabel is haeuser
not Häuser
.
The challenge is, I’m not a programmer so I have to fight my way through this…