Hello,
I’m struggling to set up tags with restricted options in a multilingual site, and I feel like I’m missing something.
My goal is simple (I don’t want a full WordPress-like taxonomy):
- I have a list of films
- I want only two categories
- I want URLs like:
/films/tag:Catalogue
/en/movies/tag:Catalog
or, if tags must be unique internally, this will be OK:
/films/tag:catalog
/en/movies/tag:catalog
My blueprint :
tags:
type: tags
label:
en: Categories
fr: Catégories
width: 1/4
options:
catalogue:
fr: Catalogue
en: Catalog
in-development:
fr: En développement
en: In development
My template :
$tagMap = [
'catalogue' => ['fr' => 'Catalogue', 'en' => 'Catalog'],
'in-development' => ['fr' => 'En développement', 'en' => 'In development']
];
$movies = $page->children()->listed();
$allTags = $movies->pluck('tags', ',', true);
$activeTagSlug = param('tag');
if ($activeTagSlug && in_array($activeTagSlug, array_keys($tagMap))) {
$movies = $movies->filterBy('tags', $activeTagSlug, ',');
}
<?php foreach ($allTags as $tagItem): ?>
<?php
$tagLabel = $tagMap[$tagItem][kirby()->language()->code()] ?? $tagItem;
$isCurrent = ($activeTagSlug === $tagItem) ? 'is-current' : '';
$tagUrl = $page->url() . '/tag:' . $tagItem;
?>
<li>
<a href="<?= $tagUrl ?>" class="btn btn--semi <?= $isCurrent ?>">
<?= html($tagLabel) ?>
</a>
</li>
<?php endforeach ?>
My question, what is the cleanest and recommended way in Kirby to have clean URLs and avoid maintaining a manual tag mapping in templates with $tagMap?
Am I using the tags field wrong, or is this a known limitation?
Thanks in advance!