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


— 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:

Controller of projects.php template:


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 ?


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


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