Tags without spaces and critical characters

a little question:

I am using split to generate a series of class in my templete.
The problem is with a tag consisting of more than one word.
one word tag: red, blue, yellow, ecc.
two words tag: light blue, warm gray, ecc.

To solve tihs problem I try to use escape() but doesn’t work with split I think.
My goal is: “light blue” become “lightblue” or “light-blue” automatically

<?php foreach($page->tags()->split(',') as $tag): ?>
<?= $tag->escape() ?>
 <?php endforeach ?>

There is another field method can I use?


You can use

echo str::slug($tag);

Please note that $tag is not a field object, but just a string (the split methods returns an array), so using escape() here will throw an error anyway.

If you don’t want the dash:

echo str::slug($tag, '');

Thanks a lot! It works!

Hello, I have a similer Problem here.

My tags with two words produce a url with a space in between, which logically does not work well.
The effect is, that the tags with two words will appear in the tag cloud, but when i click them, they will show any projects with these tags.
I tried to implement your solution, everywhere i could think of, but it always trows an error.

Here is every peace of code that is doing something with the my tags:

<?php foreach($tags as $tag): ?>
      <a <?php e($tag == $p, ' class="buttonActive tag"') ?> class="tag" href="<?= url('Arbeiten', ['params' => ['tag' => $tag]]) ?>">
        <?= html($tag)?>
<?php endforeach ?>

the controller:

 if($tag = param('tag')) {
 $Arbeiten = $Arbeiten->filterBy('tags', $tag, ',');}

$tags = $page->children()->listed()->pluck('tags', ',', true);

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

Would be so glade, if someone could help me with this problem.

@exeldoc The original problem posted is different and posted under Kirby 2. What is your Kirby version?

@texnixe Oh. Yes, when i downloaded the Photographer portfolio, it is kirby 3, right? Sry. I will look for another post… It seems like the same problem.

@exeldoc In any case, for special characters you have to urlencode() your tags when creating the link and urldecode() it again before filtering.

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


 href="<?= url('Arbeiten', ['params' => ['tag' => urlencode($tag)]]) ?>"


I’ve got a similar problem in my server with a kirby 2 installation. I’ve got tags with empty spaces and accents (spanish language) and the code above works perfect for changing empty spaces to + signs, but keep the accents, and the server doesn’t work well with accents when you visit the page of the tag, it gives an error caused by html encoding. Is there any way to clean accents from the tag urls?

http://websiteurl/noticias/tag:Torres+de+refrigeración -> this works in local but not in server
http://websiteurl/noticias/tag:Torres+de+refrigeracion -> This is the one i need working but it returns 0 post with that tag even when they exist.

Thank you!