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!