spaceless is not spaceless :D
- bernhard
- Member | 51
I've searched google and the only related topic was this: https://forum.nette.org/…-tag-content
Today I wanted to add a linked telephone number in my template file and I thought “I'm sure latte has a filter for that”.
Seems it does not?!
This is what I tried:
{var $phone = "+43 1 123 45 67"}
<a href="tel:{$phone|spaceless}">{$phone}</a>
// result
<a href="tel:+43 1 123 45 67">+43 1 123 45 67</a>
According to https://stackoverflow.com/…in-the-value “tel” URIs MUST NOT use spaces in visual separators…
I see that “spaceless” and “trim” etc. only remove spaced around content, but I wonder if there is any elegant solution to really remove all spaced in a string?
Thx!
PS: IMHO spaceless and strip should behave differently. spaceless should remove all spaces whereas strip should behave like it already does. I see that this would mean a breaking change though. But I think a “removeallspaces” filter would be good to have!
Last edited by bernhard (2023-01-12 15:15)
- nightfish
- Member | 517
@bernhard According to the documentation it does not remove spaces, merely replaces consecutive whitespace with a single character.
For your usecase I usually use {$phone|replace:' ', ''}
. Beware
it only works when the whitespace is a space character.
- David Grudl
- Nette Core | 8218
The name is probably not ideal, it should just eliminate unnecessary spaces (is meant as “less spaces”).
- bernhard
- Member | 51
Yep, agree :) Of course once I read the details in the docs it was obvious, but if you only look at the overview it is not:
https://i.imgur.com/2v11ied.png
If you find time maybe it would be nice to adjust the description on that page (https://latte.nette.org/en/filters) so that it says “unnecessary spaces” as you suggested. On this page it already does: https://latte.nette.org/en/tags
Thx for the replace solution @nightfish :)
- David Grudl
- Nette Core | 8218
Feel free to send a correction, see the box at the bottom of each page.