URL problem with tag filtering

Maybe I am the only one but on my side I have a problem with the url tags contain a space.
Example for the tag “website design”, the URLs do not work:

— projects/tag:website+design

or

— projects/tag:website%20design

An idea of the problem ?
I looked at the doc (https://getkirby.com/docs/cookbook/content-structure/filtering-with-tags) but maybe I missed some things…

Use urlencode() and urldecode() when working with spaces.

Does not work for my code.
(I specify that I speak of the page “project” and not of the parent page “projects”.)
“Projects” being the homepage.

My code on project.php:

<?php foreach(str::split($page->tags()) as $tag): ?>
<a href="<?= url('tag:' . urlencode($tag)) ?>"><?= $tag; ?></a>
<?php endforeach ?>

And the code where the filtering takes place?

My code is the same as this one:
https://getkirby.com/docs/cookbook/content-structure/filtering-with-tags

Controller of projects.php template:

<?php

return function($page) {

  // fetch the basic set of pages
  $projects = $page->children()->listed()->flip();

  // add the tag filter
  if($tag = param('tag')) {
    $projects = $projects->filterBy('tags', $tag, ',');
  }

  // fetch all tags
  $tags = $projects->pluck('tags', ',', false);

  // apply pagination
  $projects   = $projects->paginate(9);
  $pagination = $projects->pagination();

  return compact('projects', 'tags', 'tag', 'pagination');

};

I just added this code in my project.php template:

<?php foreach(str::split($page->tags()) as $tag): ?>
<a href="<?= url('tag:' . urlencode($tag)) ?>"><?= $tag; ?></a>
<?php endforeach ?>

It works great on a version of Kirby 2

Hmm ok ok
I added the code but it would be nice to put it in the documentation…
Why does it work with Kirby 2 ?

Changed:

if($tag = param('tag')) {

on:

if($tag = urldecode(param('tag'))) {

It didn’t work with Kirby 2 with spaces (or other funny characters) without the urlencode/decode stuff… and therefore this forum has multiple question regarding spaces in tags…

I just ran into this myself… by bringing over working code from K2. It worked for me too with K2 without the urldecode.

Maybe you used the tagcloud plugin?

Nope. I did it like the cookbook (for Kirby 2) said. I did have a tag cloud on the site, but I wrote it by hand without a plugin. Weird. I just lifted the same code into the Kirby 3 version of my site and found this issue.

:open_mouth: You were right! It doesn’t work. I just played close attention to my website (thats been online for about 2 years) and it does indeed not filter with a space in the tag. It didn’t break or throw a whoops or anything though… but i just double checked the list of matches it returned and it brings back all of them.

Of course you were right @texnixe

Sorry to bump this thread up again, but this has stopped working for me, with 3.1.0 and 3.1.1. My controller looks like this…

<?php

return function($kirby, $site, $pages, $page) {

  // Import Global Controller
  require_once kirby()->root('controllers') . '/shared/global.php';

  // Template Code
  // fetch the basic set of pages
  $worklist = $kirby->collection("work");

  // add the tag filter
  if($tag = urldecode(param('tag'))) {
    $worklist = $worklist->filterBy('tags', $tag, ',');
  }

  $tags = $kirby->collection("work")->pluck('tags', ',', true);

  asort($tags);

  $currenttag = $kirby->request()->params()->tag();

  return [
    'worklist' => $worklist,
    'tags' => $tags,
    'currenttag' => $currenttag

  ];

};

What exactly doesn’t work as expected anymore? Does the code throw an error? Does the filtering not work?

The tag with the space does not work (“Web Design”). All the others work fine. You can see what happens on this web page.

What’s wrong there? Seems to filter only webpages? Is the project code publicly available anywhere?

Not publicly. It’s in a private Bitbucket repo i could give you access to if you DM me account to add to the the access list.

Its filtering types of work, which works fine unless you click on “Web Design.”

What do you expect to get under web design? I get 9 results for web design? Which is 9 out of 10 altogether. So some filtering seems to be in place.

It should be lighting up the current tag in pink, but its not, and there are 10 work items in total.

Ok, I sent you a PM

The problem is that your tag link is not urlencode()d. So the problem is not in the controller, but in the template.