Hi - I am using tags to filter various pages in Kirby 4, and am trying to use custom url’s without affecting the displayed text for the tag itself.
For example, I have a tag with the value ‘video & photography’ but I want the url for this to read
‘/projects/tag:video-photography’
I had initially thought I could use the following in my blueprint:
options:
- value: video & photography
text: video & photography
But now know this won’t have an affect. I have done some digging and read that I can use translations, but can’t find an example of how to do this in the config file, or how it could work with the new translations feature in kirby 4.
Are there any solid examples I can use? Thanks!
Controller:
<?php
return function($page) {
// fetch the basic set of pages
$projects = $page->children()->listed()->flip();
// fetch all tags
$tags = $projects->pluck('tags', ',', true);
// add the tag filter
if($tag = param('tag')) {
$projects = $projects->filterBy('tags', $tag, ',');
}
// apply pagination
$projects = $projects->paginate(10);
$pagination = $projects->pagination();
return compact('projects', 'tags', 'tag', 'pagination');
};
Well I’d like to use the key value pairs in case I have more complex renaming - however can see there is a new translations feature. Either way I can’t find any documentation at all about key value pairs in either the config file or in the panel (v4) for this purpose and was hoping I could be steered towards something. Thanks
The main problem is that it is not clear what you want to achieve. What do you exactly mean when you say “translate”. For me that means I translate English “hello” to German “hallo”. So that is the first issue.
Then next:
What’s the point here? Value and text are exactly the same. But in general, yes, you can assign text and value to a tags field: Tags | Kirby CMS, paragraph below autocomplete.
I can’t find the link now, but I had read somewhere else on the forum where it was suggested to use kirby 4’s new translation feature via the panel rather than manually adding key value pairs directly in the config.
As for the example of the value and text from my blueprint, this was just an example I wrote out, it should have had something more like this:
options:
- value: video-photography
text: video & photography
However it’s a little immaterial as I can’t retrieve the text, only the value, as covered here.
If v4 doesn’t change the approach that’s fine, I just want to find a signle cookbook article/tutorial/post about how to add a map of key value pairs in config for custom tag url’s.
Ok, guess you mean the new feature to translate language variables from the Panel.
And of course, you could add your values like value: video-photography there and translate it, so that you could use it later in the frontend. But you would have to do that manually.
That’s right. But it sounds like i’m on a red herring. For now I’m just going back to the drawing board and going to try removing spaces and any ‘&’ symbol. I’m a little stuck on whether to use urldecode or slugify for this. I have attempted to use urldecode for this but it’s not having any effect which is odd - no errors but no change in the url.
Here you should normally urlencode, not decode, but that is unnecessary, because Kirby takes care of this automatically when you use the url() function with params.